-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use MiniJinja for templating #83
base: main
Are you sure you want to change the base?
Conversation
e913b61
to
be3f8f6
Compare
Are there specific kinds of flexibility this may enable for existing hebbot users that isn't currently possible? it possible this could be done behind some kind of feature flag or opt-in in the config (maybe by adding jekyll-style front-matter to the top of the markdown files) so that existing users can opt out if they dont need the extra features? Personally I love the simplicity of the current markdown templates as they currently are and haven't yet run into a situation where they weren't sufficient. The new sample markdown in this MR feels to me like a very sharp/sudden change that existing users who are used to the simplicity of the current markdown templating may not find worthwhile to migrate to unless they need to include some kind of additional plugins or other advanced things that are only possible with minijinja |
@MoralCode My initial motivation was being able to customize date formats because I wanted to use Hebbot for monthly updates. Then I figured that bringing in a template engine would allow me to generate HTML (or any other textual format) as well without needing to hardcode the formatting in |
1395eff
to
8dc9502
Compare
The render_template() function is only used once, and after making the minijinja::Environment instance a static singleton it does not contain much code, so it makes more sense to invoke the template rendering directly instead of going through an additional function call.
Bubble up Jinja errors to the caller, and send a message with the error to the admin room on failures, instead of letting the process crash at .unwrap() calls.
Use the "random" filter from the minijinja-contrib crate, instead of a custom one. This removes a little bit of code from render.rs.
This patch series replaces the custom templating from Hebbot with MiniJinja, which is a complete templating engine for Rust based on the popular Jinja2 one. This makes Hebbot output much more flexible and customizable, and allows to producing all kind of text-based output formats.
The patch set starts by updating the dependencies, which was needed in order to satisfy some of the minimum versions of some crates required by MiniJinja; then it adds the new templating code and removes the old one iteratively. Lastly, example configurations and documentation are brought up-to-date.
The updated example configuration should produce (almost) the same output as before.