From 8f558ce0b82f74362ce71a6407b2df9dee7d0349 Mon Sep 17 00:00:00 2001 From: User Identifier Date: Fri, 17 Nov 2017 15:08:02 +0100 Subject: [PATCH] Support multiple templates --- ciclostile.py | 5 ++++- example/markdown/test_other_template.md | 8 ++++++++ example/{template.html => templates/default.html} | 0 example/templates/other_template.html | 11 +++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 example/markdown/test_other_template.md rename example/{template.html => templates/default.html} (100%) create mode 100644 example/templates/other_template.html diff --git a/ciclostile.py b/ciclostile.py index e116413..16bd01e 100755 --- a/ciclostile.py +++ b/ciclostile.py @@ -3,7 +3,7 @@ import os import markdown import jinja2 -template_file = 'template.html' +template_path = 'templates' md_path = './markdown' html_path = './target' @@ -15,6 +15,9 @@ def write_page(page, out_name): def render_page(data): + template_name = data.get('template', 'default') + template_file = os.path.join(template_path, template_name + '.html') + with open(template_file) as f: template = f.read() diff --git a/example/markdown/test_other_template.md b/example/markdown/test_other_template.md new file mode 100644 index 0000000..fa0ebbe --- /dev/null +++ b/example/markdown/test_other_template.md @@ -0,0 +1,8 @@ +Title: Other Test Page +Template: other_template + + +# Title + +Some other text + diff --git a/example/template.html b/example/templates/default.html similarity index 100% rename from example/template.html rename to example/templates/default.html diff --git a/example/templates/other_template.html b/example/templates/other_template.html new file mode 100644 index 0000000..a1939c6 --- /dev/null +++ b/example/templates/other_template.html @@ -0,0 +1,11 @@ + + + + {{ title }} + + + +

Other Template

+ {{ content }} + +