Commit 954e4051 authored by Marien Fressinaud's avatar Marien Fressinaud

add: Allow overriding articles and pages templates

parent 0b0f035d
......@@ -334,6 +334,9 @@ This will generate the `site/my_page.html` file:
</html>
```
You can override the default template by setting a `template` variable in the
Yaml header of pages and articles.
## Template syntax
As explained above, you can create templates under the `./templates` folder.
......
......@@ -52,6 +52,7 @@ class Article:
self.meta = {}
self.meta.update(configuration)
self.meta["ARTICLE_SLUG"] = slug
self.meta["ARTICLE_TEMPLATE"] = "article"
for key, values in md.Meta.items():
article_key = f"ARTICLE_{key.upper()}"
# The Markdown's meta extension extract all the values in arrays, even
......@@ -63,7 +64,9 @@ class Article:
self.meta["ARTICLE_CONTENT"] = content
# And we initialize a template for the article
article_template_filepath = os.path.join("templates", "article.html")
article_template_filepath = os.path.join(
"templates", f"{self.meta['ARTICLE_TEMPLATE']}.html"
)
self.template = boopsy.Template(article_template_filepath)
def render(self):
......@@ -123,6 +126,7 @@ class Page:
self.meta = {}
self.meta.update(configuration)
self.meta["PAGE_SLUG"] = slug
self.meta["PAGE_TEMPLATE"] = "page"
yaml_conf, page_content = extract_yaml_configuration(page_content)
for key, value in yaml_conf.items():
article_key = f"PAGE_{key.upper()}"
......@@ -130,7 +134,9 @@ class Page:
self.meta["PAGE_CONTENT"] = page_content
# And we initialize a template for the page
page_template_filepath = os.path.join("templates", "page.html")
page_template_filepath = os.path.join(
"templates", f"{self.meta['PAGE_TEMPLATE']}.html"
)
self.template = None
if os.path.exists(page_template_filepath):
self.template = boopsy.Template(page_template_filepath)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment