getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
12.98k stars 919 forks source link

Register a function in Tera #2493

Open MaoHolden opened 2 months ago

MaoHolden commented 2 months ago

Register a Tera function in order to execute complex logic like calculating read time.

Summary

Zola uses the Tera engine, I would like to calculate the read time of my markdown posts. One way I thing it could be done is by adding a Rust function in the Tera engine using tera.register_function but I don't see how this can be done in the documentation.

Proposed solution

Either specify that its not possible yet or document how.

Greetings

Thank you for the great framework 🤩.

Keats commented 2 months ago

It's not possible currently. For the next version of Tera, i'm thinking of allowing some scripting language like https://rhai.rs/ or wasm functions. Not coming anytime soon though.

MaoHolden commented 2 months ago

Got it, sounds like a cool idea :). I was checking the docs I the only place I see to put a comment about this is in /documentation/templates/overview/. You reckon its useful or just with this Issue is enough?

Keats commented 2 months ago

Note that for this specific feature we do have a very crude version. See reading_time in https://www.getzola.org/documentation/templates/pages-sections/ Was it for a non latin language?

MaoHolden commented 2 months ago

Yeah I'm using that already :). Thanks!.

Also if you want I could make a PR with a small comment about not having support for registering custom functions to Tera. If you don't think its necessary you can just close the Issue 🙂

Keats commented 2 months ago

sure but I think right now it's implicit it's not supported. It wouldn't hurt to write it int he docs though