zola icon indicating copy to clipboard operation
zola copied to clipboard

[Flow recommendation] Executing an arbitrary program as Tera filter to customize a template

Open Arteneko opened this issue 2 years ago • 3 comments

Okay, so this is gonna be weird.

But, I have a very specific thing I'd like to do on my blog, and I'm not sure Tera is able to do it.

I have a bunch of pages. Lots of them. I would like to make them have their own little color scheme for "theme flags".

My original plan was to do something like the following "small" algorithm (which obviously has no reason to land in Zola, as it's extremely specific).

  • Take the page's "absolute" URL (absolute from the server root)
  • Compute its XXHash value
  • Return xxhash(absolute_url) % count(color_schemes) (ie pick one color scheme based on the absolute URL's hash, deterministic for a single page, but random enough for every possible URL I have)

I would guess that making a script do this job, and offloading it in a separate process that would be invoked on every page render would be perfect, but I'm not sure if Zola is able to do so... Or if I should make a post-build step to add this quirk. Any recommendation ? (I will, for now, go for the post-build step because I'd like to get it up soon, but if there's a cleaner way, I'd appreciate it)

Arteneko avatar Dec 06 '21 00:12 Arteneko

but I'm not sure if Zola is able to do so...

It's not. It would work if there was a hash filter exposed by Zola but it's probably a usecase too small to be added. Maybe if more people need it.

Keats avatar Dec 06 '21 19:12 Keats

It goes beyond hashing. Hi, reviving this! =)

I also have custom UUID generation for all blog posts. And i have a very specialised image processing workflow that is incompatible with Zola’s: Downscale into 4 specific sizes, save as AVIF, generate an <img srcset="…" sizes="…" … /> shortcode for that specific image.

It doesn’t even have to be cross-platform. Filter scripts could exist per OS, like myfilter.linux.lua, myfilter.windows.exe, or whatever. It’s just me and my blog, the only ones running the builds are my Linux-based CI/CD runners and my Linux-based PC.

I would recommend embedding a scriptlang like Lua, though. (No preferrence, actually, i’ll use whatever is included and works.) That limits the OS-specific parts to just »are these tools/libs i need installed«. And you can pass config, parameters, and other state, much cleaner to a scriptlang.

Just seen #1544 , which is basically what i’m suggesting.

Evrey avatar Feb 25 '24 08:02 Evrey

See https://github.com/Keats/tera/issues/637#issuecomment-1891976443 as well. That would be in Tera but not coming anytime soon

Keats avatar Feb 26 '24 14:02 Keats