Skip to content

[Regression] Doesn't build without top-level templates directory #2150

@vimpostor

Description

@vimpostor

Since version 0.17.1 zola requires the top-level /templates directory to exist, even if a theme is used. Otherwise it will fail with:

Error: Failed to build the site
Error: Error parsing templates from the /templates directory
Error: Reason: Io error while writing rendered value to output: NotFound
Error: Reason: No such file or directory (os error 2)

This is because now tera handles globs differently, as discussed in Keats/tera#819 (comment).

I believe that this is not very user-friendly, as it can quickly lead to unexpected build failures with the default setup as follows:

  • Run zola init mysite
  • Run zola serve
  • The official default index.html says that you should either add an index.html or add a theme to use
  • You decide for the second option and add a theme, which leaves the top level templates directory empty
  • It builds fine, so you push to a git repo
  • Now pulling on a different machine or on CI will cause zola to fail building the site, because there is no templates directory checked into git

In my opinion this is not optimal, and zola should still work if there is no top-level templates directory.

The following patch fixes the problem from zola's side:

diff --git a/components/templates/src/lib.rs b/components/templates/src/lib.rs
index 6441ff49..e2747bfc 100644
--- a/components/templates/src/lib.rs
+++ b/components/templates/src/lib.rs
@@ -47,8 +47,7 @@ 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 = Tera::parse(&tpl_glob).unwrap_or(Tera::default());
 
     if let Some(ref theme) = config.theme {
         // Test that the templates folder exist for that theme

However it's not really a good solution, because it will shadow actual parsing problems if /templates exists and there are real problems. This is why I believe this problem is better fixed on tera's side, i.e. making invalid globs just return the empty set instead of an error, which is how it is done in most languages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions