1
0
flewkey.com/scripts/gen_blog.py

33 lines
920 B
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import markdown
def gen_list(files, ext, limit=-1, mini=False):
from template import template
md = markdown.Markdown(extensions = ["meta", "extra"])
items = ""
i = 0
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" if not mini else "post_preview_mini"
items += template(html, "blog/"+post[:-3]+ext, ext, md.Meta)
i += 1
if limit >= 0 and i >= limit:
break;
return items
def main():
from template import template
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()