-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_tag.py
49 lines (39 loc) · 1.01 KB
/
update_tag.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import shutil
import time
import threading
def update_all():
fromCatDir = "./_site/_cat"
fromTagDir = "./_site/_tag"
destCatDir = "./cat"
destTagDir = "./tag"
catTpl = '''---
layout: catpage
tag: %s
---'''
tagTpl = '''---
layout: tagpage
tag: %s
---'''
gen(fromCatDir, destCatDir, catTpl)
gen(fromTagDir, destTagDir, tagTpl)
def gen(from_dir, to_dir, tpl):
if os.path.exists(to_dir):
shutil.rmtree(to_dir)
time.sleep(1)
os.mkdir(to_dir)
if os.path.exists(from_dir):
for root,dirs,files in os.walk(from_dir):
for f in files:
fs = open(os.path.join(root, f), 'r')
text = fs.read()
fs.close()
md = os.path.join(to_dir, text + '.md')
ws = open(md, 'w')
ws.write(tpl % (text))
ws.close()
print(os.path.abspath(md))
if __name__ == '__main__':
update_all()