From 64885aa4f1fb189d6188fe2d5ffa96d534541f4b Mon Sep 17 00:00:00 2001 From: Midgard <2885-Midgard@users.noreply.framagit.org> Date: Tue, 2 Jun 2020 02:43:17 +0200 Subject: [PATCH] Add templating for list of blog posts --- blog/feeds.md | 5 +++++ blog/irc.md | 5 +++++ do_index.py | 26 ++++++++++++++++++++++++++ index.html | 10 +--------- 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 blog/feeds.md create mode 100644 blog/irc.md create mode 100755 do_index.py diff --git a/blog/feeds.md b/blog/feeds.md new file mode 100644 index 0000000..90ebeac --- /dev/null +++ b/blog/feeds.md @@ -0,0 +1,5 @@ +title: Get started using feeds +summary: Pick a client, add some feeds, done +published: 2020-06-02 + +--- diff --git a/blog/irc.md b/blog/irc.md new file mode 100644 index 0000000..330fbb6 --- /dev/null +++ b/blog/irc.md @@ -0,0 +1,5 @@ +title: Get started with IRC +summary: Pick a client, join some channels, maybe register with NickServ +published: 2020-06-02 + +--- diff --git a/do_index.py b/do_index.py new file mode 100755 index 0000000..d6d778e --- /dev/null +++ b/do_index.py @@ -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 = """ +
  • +
    {title}
    +
    {summary}
    +
  • """ + +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) diff --git a/index.html b/index.html index b6fd69a..bf74775 100644 --- a/index.html +++ b/index.html @@ -16,15 +16,7 @@

    Blog

    -