Skip to content
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

Allow empty templates dir #2153

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.18.0 (unreleased)

- Fix error on missing top-level `templates` directory.

## 0.17.2 (2023-03-19)

- Fix one more invalid error with colocated directories
Expand Down
16 changes: 9 additions & 7 deletions components/templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ pub fn render_redirect_template(url: &str, tera: &Tera) -> Result<String> {
}

pub fn load_tera(path: &Path, config: &Config) -> Result<Tera> {
let tpl_glob =
format!("{}/{}", path.to_string_lossy().replace('\\', "/"), "templates/**/*.{*ml,md}");

// Only parsing as we might be extending templates from themes and that would error
// as we haven't loaded them yet
let mut tera =
Tera::parse(&tpl_glob).context("Error parsing templates from the /templates directory")?;
let mut tera = if path.join("templates").exists() {
let tpl_glob =
format!("{}/{}", path.to_string_lossy().replace('\\', "/"), "templates/**/*.{*ml,md}");
// Only parsing as we might be extending templates from themes and that would error
// as we haven't loaded them yet
Tera::parse(&tpl_glob).context("Error parsing templates from the /templates directory")?
} else {
Tera::default()
};

if let Some(ref theme) = config.theme {
// Test that the templates folder exist for that theme
Expand Down