Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Setup HTML Escaping For Files With A Different Extension In Minijinja

Code

use minijinja::AutoEscape;

fn create_env(path: &str) -> Environment<'static> {
    let mut env = Environment::new();
    env.set_source(Source::from_path(path));
    env.set_auto_escape_callback(|name| {
    if matches!(name.rsplit('.').next().unwrap_or(""), "html" | "jinja") {
        AutoEscape::Html
    } else {
        AutoEscape::None
    }
});
    env
}