spanezz / staticsite

Static site generator
GNU General Public License v3.0
45 stars 7 forks source link

Make .j2. hack go away #32

Closed spanezz closed 4 years ago

spanezz commented 4 years ago

Currently the .j2. marker in file names is used to distinguish static assets from jinja2 templates.

Now that we have directory metadata, we potentially have a way to tell the j2 feature a list or glob of files to read as templates regardless of their name.

For example, a .staticsite file could have a way to pass information to features:

features:
   j2:
      files: [*.html]

this seems rather verbose. Alternatively, allow files to be a glob, and use its metadata to communicate with features:

files:
   *.html:
      feature: jinja2

this sounds flexible but not really straightforward. Another option can be to say that if one provides extra metadata for a .html file, then the j2 feature would automatically consider it a template:

files:
   index.html:
      title: "Enrico's interesting site"

And if in the future this causes static assets to be wrongly interpreted as templates, one could easily add a static: yes metadata to disable it on a file by file basis.

spanezz commented 4 years ago

Another option: open .html files, look at the first line. If it's {#---, {#{, or {#+++, parse until the first line that ends with #} as front matter, and use it as a template. Otherwise, consider it an asset.

spanezz commented 4 years ago

Another option:

spanezz commented 4 years ago

It's possible to get at a block in a compiled jinja2 template: we can cleanly have front matter in jinja2 as:


{% block front_matter %}
---
title: Page title
{% endblock %}