#!/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[3:]) | 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 ).data with open(sys.argv[2]) as file_in: print( file_in.read().format(blog_posts=blog_post_list), end="" ) else: metadata = safe_metadata(blog_page_metadata(sys.argv[1])) body = blog_page_body(sys.argv[1]) print( blog_page_template().format(**metadata, body=body), end="" ) if __name__ == '__main__': main()