-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepost.py
73 lines (61 loc) · 1.51 KB
/
prepost.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#-*_coding:utf8-*-
import yaml
import os
import sys
tagSet = set()
def check(filename):
# print(filename)
f = open(filename, encoding="utf8")
s = ''
time = 0
while(True):
tmp = f.readline()
# print(tmp)
if len(tmp) > 0:
if tmp[0] == '-':
time = time + 1
s = s + tmp
if time == 2:
break
data = yaml.load_all(s, Loader=yaml.SafeLoader)
time = 0
for i in data:
if time >= 1:
break
time = time + 1
for j in i['tag']:
tagSet.add(j)
def create(tagName):
if not os.path.exists('./tag/' + tagName):
os.makedirs('./tag/' + tagName)
f = open('./tag/' + tagName + '/index.html', 'w', encoding='utf8')
print(
'''---
layout: default
title: Tags
header: Posts By Tag
---
<div class="container docs-container" id="js-to-remove">
<div class="panel docs-content">
<div class="wrapper">
<div class="home">
{% for tag in site.tags %}
{% if tag[0] contains \'''' + tagName +
'''\'%}
<h2 id="{{ tag[0] }}-ref">{{ tag[0] }}</h2>
<ul>
{% assign pages_list = tag[1] %} {% include LessOrMore/pages_list %}
</ul>
{% endif %}
{% endfor %}
</div>
</div>
</div>
</div>
''', file=f)
for root, dirs, files in os.walk('./_posts'):
for filename in files:
check(os.path.join(root, filename))
for i in tagSet:
# if not os.path.isfile('./tag/'+i+'/index.html'):
create(i)