diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2016-11-15 15:16:23 +0100 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2016-11-15 15:16:23 +0100 |
commit | bda028e1db07d786ec0cf48feeae199679f07d70 (patch) | |
tree | 2f12358e308c41ed5d5f48e281f35c817e914522 | |
parent | 5f78f881b64e451c446f5f69b71a1dad0eae9fa3 (diff) | |
download | kyblo-bda028e1db07d786ec0cf48feeae199679f07d70.tar.xz |
Add support for entry tags
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
-rwxr-xr-x | scripts/build.py | 21 | ||||
-rw-r--r-- | templates/entry.html | 10 | ||||
-rw-r--r-- | templates/layout.html | 14 | ||||
-rw-r--r-- | templates/tags.html | 12 |
4 files changed, 54 insertions, 3 deletions
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) diff --git a/templates/entry.html b/templates/entry.html index f44567a..619c429 100644 --- a/templates/entry.html +++ b/templates/entry.html @@ -9,6 +9,16 @@ <div> {{ content }} </div> + <footer> + {% if 'tags' in entry %} + <div id="tags"> + Tags: + {% for tag in entry['tags'] %} + <a href="tag-{{ tag }}.html">{{ tag }}</a> + {% endfor %} + </div> + {% endif %} + </footer> </article> <nav> <div id="post-nav"> diff --git a/templates/layout.html b/templates/layout.html index 2d5c415..beb8c5d 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -35,6 +35,15 @@ header nav a:hover { article p { white-space: pre-wrap; } +#tags { + padding-bottom: 0.25em; +} +#tags, #tags a { + color: #444; +} +#tags a:hover { + color: #111; +} #post-nav { padding-bottom: 0.25em; } @@ -42,6 +51,10 @@ ul#archive-list { list-style-type: none; padding-left: 0; } +ul#tag-list { + list-style-type: circle; + padding-left: 2em; +} footer p#copy { margin: 0em; padding-top: 0.25em; @@ -67,6 +80,7 @@ footer ul#contact-info li { <ul> <li><a href="index.html">index</a></li> <li><a href="archive.html">archive</a></li> + <li><a href="tags.html">tags</a></li> <li><a href="about.html">about</a></li> </ul> </nav> diff --git a/templates/tags.html b/templates/tags.html new file mode 100644 index 0000000..b795e5e --- /dev/null +++ b/templates/tags.html @@ -0,0 +1,12 @@ +{% extends 'layout.html' %} + +{% block content %} +<section> + <h1>{{ title }}</h1> + <ul id="tag-list"> + {% for tag in entries %} + <li><a href="tag-{{ tag }}.html">{{ tag }}</a> ({{ entries[tag] }})</li> + {% endfor %} + </ul> +</section> +{% endblock %} |