1
0
flewkey.com/scripts/gen_blog.py
2020-07-13 02:35:49 +00:00

28 lines
771 B
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import markdown
from template import template
def gen_list(files, ext):
md = markdown.Markdown(extensions = ["meta", "extra"])
items = ""
for post in files:
with open("posts/"+post, "r", encoding="utf-8") as file_in:
html = md.convert(file_in.read())
md.Meta["template"] = "post_preview"
items += template(html, "blog/"+post[:-3]+ext, ext, md.Meta)
return items
def main():
meta = {"template": "post_list"}
ext = "."+sys.argv[2].split(".")[-1]
files = sorted(os.listdir(sys.argv[1]), reverse=True)
output = template(gen_list(files, ext), sys.argv[2], ext, meta)
with open(sys.argv[2], "w+", encoding="utf-8") as file_out:
file_out.write(output)
if __name__ == "__main__":
main()