-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.py
executable file
·30 lines (26 loc) · 1.16 KB
/
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
#!/usr/bin/env python3
# Author: Brendan Gregos
# Description: Basic site generator for vtluug-site. Reads from template.html and
# creates a page for each *.txt in the pages folder. For each page generated,
# the template is inserted and <!--*content--> is replaced with the content of
# each .txt file. The outputted filename is <name>.html for each page's <name>.txt
import os
template = open("template.html","r")
lines = template.readlines()
template.close()
for root, dirs, files in os.walk("./pages"):
for file in files:
if file.endswith(".txt"):
createdFile = open(file[:-4]+".html","w")
print("creating "+file[:-4]+".html")
for line in lines:
if "<!--*content-->" not in line:
createdFile.write(line)
else:
replacmentString = ""
contentFile = open("./pages/"+file, "r")
for s in contentFile.readlines():
replacmentString += s
createdFile.write(line.replace("<!--*content-->", replacmentString))
contentFile.close()
createdFile.close()