#!/usr/bin/env python3 import sys import re from markdown import markdown from strictyaml import load as load_yaml from pymaybe import maybe as maybe from functools import partial as p from ipo import read, write, dictmap, starstarmap, ipo, all_before, all_after LIST_ITEM_TEMPLATE = """
", "").replace("
", "") ) for k, v in metadata.items() } def main(): if sys.argv[1] == "--index": blog_post_list = ( ipo(sys.argv[4:]) | p(map, blog_page_metadata) | p(sorted, key=lambda x: x["published"]) | p(map, safe_metadata) | p(map, lambda metadata: LIST_ITEM_TEMPLATE.format(**metadata)) | "".join ) with open(sys.argv[2]) as file_in, open(sys.argv[3], "w") as file_out: print( file_in.read().format(blog_posts=blog_post_list), end="", file=file_out ) else: metadata = safe_metadata(blog_page_metadata(sys.argv[1])) body = blog_page_body(sys.argv[1]) with open(sys.argv[2], "w") as file_out: print( blog_page_template().format(**metadata, body=body), end="", file=file_out ) if __name__ == '__main__': main()