-
Notifications
You must be signed in to change notification settings - Fork 67
/
gen_catalog.py
51 lines (42 loc) · 1.24 KB
/
gen_catalog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# coding: utf-8
from utils import load_mds
def gen_catalog(posts_dir, output_file, headers, footers):
articles = load_mds("./articles")
with open(output_file, "w+") as f:
# clear all the contents in file
f.truncate()
for header in headers:
f.write(header)
f.write("\n\n")
# write catalog
for title, date, filename, path in articles:
f.write(
"- {date} - [{title}](https://jiajunhuang.com/{path}/{filename}.html)\n".format(
date=date.strftime("%Y/%m/%d"),
title=title,
path=path,
filename=filename,
)
)
for footer in footers:
f.write(footer)
f.write("\n\n")
if __name__ == "__main__":
# README.md
readme_headers = [
"# Jiajun's Blog",
"会当凌绝顶,一览众山小。",
"- [关于我](https://jiajunhuang.com/aboutme)",
"## 目录",
]
readme_footers = [
"\n",
"--------------------------------------------",
"禁止转载",
]
gen_catalog(
"articles",
"./README.md",
readme_headers,
readme_footers,
)