#!/usr/bin/env python3 import sys from glob import glob import re from strictyaml import load as load_yaml from ipo import list, str, read, write, map, starstarmap, takewhile, join, sort 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)