diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2016-11-15 14:49:36 +0100 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2016-11-15 14:49:36 +0100 |
commit | a12496341b9854669e47f9df3cd0d7886faab8b0 (patch) | |
tree | f9cbbf8d7b9481e570404b0a4f548c0ddc3f6a86 | |
parent | 8f5034eca90df98e60685cd2fcae5eb29de3d555 (diff) | |
download | kyblo-a12496341b9854669e47f9df3cd0d7886faab8b0.tar.xz |
Pass templates to build functions
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
-rwxr-xr-x | scripts/build.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/scripts/build.py b/scripts/build.py index 971b8d4..4b3eddf 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -8,8 +8,7 @@ from jinja2 import Environment, FileSystemLoader from utils.reST import reST_to_html -def build_entry(jenv, fname, entry, older=None, newer=None): - template = jenv.get_template('entry.html') +def build_entry(template, fname, entry, older=None, newer=None): source_file = 'entries/{}.rst'.format(entry['file']) with open(source_file, 'r') as f: source = f.read() @@ -24,9 +23,8 @@ def build_entry(jenv, fname, entry, older=None, newer=None): f.write(rendered) -def build_archive(jenv, filename, title, entries): - archive_template = jenv.get_template('archive.html') - rendered = archive_template.render(title=title, entries=entries) +def build_archive(template, filename, title, entries): + rendered = template.render(title=title, entries=entries) with open('out/{}.html'.format(filename), 'w+') as f: f.write(rendered) @@ -57,17 +55,19 @@ if __name__ == '__main__': jenv = Environment(loader=FileSystemLoader('templates'), trim_blocks=True, lstrip_blocks=True) + entry_tmpl = jenv.get_template('entry.html') + archive_tmpl = jenv.get_template('archive.html') published, unpublished = load_metadata('metadata.json') for entry in unpublished: - build_entry(jenv, entry['file'], entry) + build_entry(entry_tmpl, entry['file'], entry) for index, entry in enumerate(published): older = published[index-1:index] newer = published[index+1:index+2] - build_entry(jenv, entry['file'], entry, older, newer) + build_entry(entry_tmpl, entry['file'], entry, older, newer) - build_entry(jenv, 'index', published[-1], older=published[-2:-1]) + build_entry(entry_tmpl, 'index', published[-1], older=published[-2:-1]) - build_archive(jenv, 'archive', 'Archive', published) + build_archive(archive_tmpl, 'archive', 'Archive', published) |