From bda028e1db07d786ec0cf48feeae199679f07d70 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Tue, 15 Nov 2016 15:16:23 +0100 Subject: Add support for entry tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Johannes Löthberg --- scripts/build.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/build.py b/scripts/build.py index 4b3eddf..b6d4870 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -2,6 +2,7 @@ import os.path import json +from collections import OrderedDict from jinja2 import Environment, FileSystemLoader @@ -35,6 +36,7 @@ def load_metadata(name): published = [] unpublished = [] + tags = {} for entry in entries: path = 'entries/{}.rst'.format(entry['file']) @@ -48,7 +50,13 @@ def load_metadata(name): else: unpublished.append(entry) - return (published, unpublished) + for tag in entry.get('tags', []): + if not tag in tags: + tags[tag] = [] + + tags[tag].append(entry) + + return (published, unpublished, tags) if __name__ == '__main__': @@ -57,8 +65,9 @@ if __name__ == '__main__': lstrip_blocks=True) entry_tmpl = jenv.get_template('entry.html') archive_tmpl = jenv.get_template('archive.html') + tags_tmpl = jenv.get_template('tags.html') - published, unpublished = load_metadata('metadata.json') + published, unpublished, tags = load_metadata('metadata.json') for entry in unpublished: build_entry(entry_tmpl, entry['file'], entry) @@ -69,5 +78,11 @@ if __name__ == '__main__': build_entry(entry_tmpl, entry['file'], entry, older, newer) build_entry(entry_tmpl, 'index', published[-1], older=published[-2:-1]) - build_archive(archive_tmpl, 'archive', 'Archive', published) + + tag_list = OrderedDict(sorted(map(lambda k: (k, 0), tags.keys()))) + for tag in tags: + build_archive(archive_tmpl, 'tag-{}'.format(tag), tag, tags[tag]) + tag_list[tag] = len(tags[tag]) + + build_archive(tags_tmpl, 'tags', 'Tags', tag_list) -- cgit v1.2.3-70-g09d2