Add templating for list of blog posts

This commit is contained in:
Midgard 2020-06-02 02:43:17 +02:00
parent ab00f845c2
commit 64885aa4f1
Signed by untrusted user who does not match committer: midgard
GPG key ID: 511C112F1331BBB4
4 changed files with 37 additions and 9 deletions

5
blog/feeds.md Normal file
View file

@ -0,0 +1,5 @@
title: Get started using feeds
summary: Pick a client, add some feeds, done
published: 2020-06-02
---

5
blog/irc.md Normal file
View file

@ -0,0 +1,5 @@
title: Get started with IRC
summary: Pick a client, join some channels, maybe register with NickServ
published: 2020-06-02
---

26
do_index.py Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import sys
from strictyaml import load as load_yaml
from ipo import list, str, read, write, map, starstarmap, takewhile, join, sort
from glob import glob
import re
TEMPLATE = """
<li><a href="{path}">
<div class="title">{title}</div>
<div class="summary">{summary}</div>
</a></li>"""
def metadata(filename):
with open(filename) as fh:
metadata_yaml = read(fh) | takewhile(lambda line: line != "---") | join("\n")
return {
**load_yaml(metadata_yaml).data,
"path": re.sub(r".md$", "", filename)
}
blog_post_list = glob("blog/*.md") | map(metadata) | sort(key=lambda x: x["published"]) | starstarmap(TEMPLATE.format) | join("")
with open(sys.argv[1]) as file_in, open(sys.argv[2], "w") as file_out:
file_in.read().format(blog_posts=blog_post_list) | write(file=file_out)

View file

@ -16,15 +16,7 @@
<section id="blog">
<h2>Blog</h2>
<ul>
<li><a href="/blog/irc/">
<div class="title">Get started with IRC</div>
<div class="summary">Pick a client, join some channels, maybe register with NickServ</div>
</a></li>
<li><a href="/blog/rss/">
<div class="title">Get started using RSS</div>
<div class="summary">Pick a client, add some feeds, done</div>
</a></li>
<ul>{blog_posts}
</ul>
</section>