1
0
flewkey.com/scripts/gen_blog.py

33 lines
920 B
Python
Raw Normal View History

2020-07-12 22:35:49 -04:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import markdown
2020-07-22 13:43:20 -04:00
def gen_list(files, ext, limit=-1, mini=False):
from template import template
2020-07-12 22:35:49 -04:00
md = markdown.Markdown(extensions = ["meta", "extra"])
items = ""
2020-07-22 13:43:20 -04:00
i = 0
2020-07-12 22:35:49 -04:00
for post in files:
with open("posts/"+post, "r", encoding="utf-8") as file_in:
html = md.convert(file_in.read())
2020-07-22 13:43:20 -04:00
md.Meta["template"] = "post_preview" if not mini else "post_preview_mini"
2020-07-12 22:35:49 -04:00
items += template(html, "blog/"+post[:-3]+ext, ext, md.Meta)
2020-07-22 13:43:20 -04:00
i += 1
if limit >= 0 and i >= limit:
break;
2020-07-12 22:35:49 -04:00
return items
def main():
2020-07-22 13:43:20 -04:00
from template import template
2020-07-12 22:35:49 -04:00
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()