27 lines
828 B
Python
27 lines
828 B
Python
|
#!/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)
|