Skip to content

Commit

Permalink
Allow an Empty templates directory
Browse files Browse the repository at this point in the history
Fixes #2150
  • Loading branch information
iwahbe committed Mar 26, 2023
1 parent 8d16d17 commit 707345d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Changelog

## 0.18.0 (unreleased)

## 0.17.2 (2023-03-19)

- Fix one more invalid error with colocated directories
Expand Down
13 changes: 10 additions & 3 deletions components/templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::Path;

use config::Config;
use libs::once_cell::sync::Lazy;
use libs::tera::{Context, Tera};
use libs::tera::{self, Context, Tera};

use errors::{bail, Context as ErrorContext, Result};
use utils::templates::rewrite_theme_paths;
Expand Down Expand Up @@ -47,8 +47,15 @@ pub fn load_tera(path: &Path, config: &Config) -> Result<Tera> {

// 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 = match Tera::parse(&tpl_glob) {
Ok(t) => t,
Err(e) if matches!(e.kind, tera::ErrorKind::Io(std::io::ErrorKind::NotFound)) => {
Tera::default()
}
Err(e) => {
return Err(e).context("Error parsing templates from the /templates directory");
}
};

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

0 comments on commit 707345d

Please sign in to comment.