Jieiku / abridge

Fast & Lightweight Zola Theme
https://abridge.pages.dev/
MIT License
142 stars 41 forks source link

Question about 'Body' variable in katex shortcode #163

Closed itstamimi closed 3 months ago

itstamimi commented 3 months ago

The 'body' variable in here https://github.com/Jieiku/abridge/blob/d45bc26c2250f573a0d83f755831857999fc125f/templates/shortcodes/katex.html#L1 it's coming from where?

I'm asking as I'm making a shortcode for something else, and the expression {{ }} I have in the short code script works fine, but because of the CSP whenever the value changes, the hash changes too making the shortcode unusable. I was looking at katex and it seems there's a way by having the expression {{ }} in the post itself rather than the script, and that might solve it, it's just I don't know the "body" variable is taken from where.

Thanks!

Jieiku commented 3 months ago

The body variable is a built in feaure of Zola:

https://www.getzola.org/documentation/content/shortcodes/#shortcodes-with-body

I had similar issues when I initially implemented a imgswap shortcode: https://abridge.netlify.app/overview-images/#imgswap-shortcode

Initially I was trying to do it in a way that the src changed, but instead I just include both image sources in the body of the page with different class names. You may have to think outside of the box depending on what your trying to accomplish.

itstamimi commented 3 months ago

The body variable is a built in feaure of Zola:

That was my initial thoughts, but I had (and still) having the following error Error: Reason: Variable `body` not found in context while rendering 'shortcodes/chat.html', no clue why.. and I thought I have to declare it somewhere else first

Initially I was trying to do it in a way that the src changed, but instead I just include both image sources in the body of the page with different class names. You may have to think outside of the box depending on what your trying to accomplish.

That's exactly my current situation, I have a short script that will be inline, the CSP is preventing it, and I thought having the integrity hash will solve it, but I have in the script a variable that changes per the post title, so the integrity won't work, Nonce aren't supported yet in Zola, my only option is trying your way 🤞

Update: There's no way to be done in Zola except: adding the nonce at Netlify level, since Zola don't support it except hardcoded one, or adding the CSP in the head file to properly manipulate it, I will do a quick write up and add it here for anyone in the same spot. Great theme btw!