28 lines
830 B
Python
Executable file
28 lines
830 B
Python
Executable file
#!/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 = """
|
|
<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)
|