From 8566d8258a960fc1456d271b25428cbd312ba42b Mon Sep 17 00:00:00 2001 From: vallentin Date: Wed, 10 Mar 2021 08:43:01 +0100 Subject: Fixed extension to ignore common jinja extensions (fixes #457) --- askama_shared/src/input.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'askama_shared/src') diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index be380ea..febd51c 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -205,7 +205,17 @@ impl<'a> TemplateInput<'a> { } fn extension(path: &Path) -> Option<&str> { - path.extension().map(|s| s.to_str().unwrap()) + let ext = path.extension().map(|s| s.to_str().unwrap())?; + + const JINJA_EXTENSIONS: [&str; 3] = ["j2", "jinja", "jinja2"]; + if JINJA_EXTENSIONS.contains(&ext) { + Path::new(path.file_stem().unwrap()) + .extension() + .map(|s| s.to_str().unwrap()) + .or(Some(ext)) + } else { + Some(ext) + } } pub enum Source { -- cgit