-
Notifications
You must be signed in to change notification settings - Fork 2
/
tag_generator.py
45 lines (36 loc) · 1.06 KB
/
tag_generator.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
import glob
import ruamel.yaml as yaml
import io
blog_posts = glob.glob("_posts/*")
tags = set([])
for blog_post in blog_posts:
with open(blog_post) as stream:
try:
docs = yaml.load_all(stream)
for doc in docs:
try:
for item in doc.items():
if item[0] == "categories":
new_set = set(item[1])
tags.update(new_set)
# if item[0] == categories:
# print(item[1])
# # tags.extend(item[1])
except:
print(".")
except yaml.YAMLError as exc:
print(exc)
print(tags)
print(len(tags))
def create_tag_template(tag):
html_content = """---
layout: tags
title: {}
category: {}
---""".format(tag, tag)
file_path = "tags/" + tag + ".html"
print(html_content)
with io.FileIO(file_path, "w") as file:
file.write(html_content.encode('utf-8'))
for tag in tags:
create_tag_template(tag)