-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
131 lines (105 loc) · 3.34 KB
/
build.py
File metadata and controls
131 lines (105 loc) · 3.34 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import glob # look into pathlib
import os
import importlib
from importlib.machinery import SourceFileLoader
import string
import random
from pathlib import Path
# gen proj page
def generateProjectPage(project):
print(project['path'])
# print((project['texts'].description))
link = (project['texts'].title.replace(" ", "") + ".html").lower()
print(link)
proj = open(link, 'w+')
projHtml = str(projHtmlTemp)
content = ""
if project['content']:
for index, item in enumerate(project['content']):
print(item)
# image
if Path(item).suffix in [".png", ".gif", ".pdf"]:
content += """<img src='%s/%s'/>\n""" % (project['path'], item)
# then description
if index == 0 and project['texts'].description:
content += """<p class="description">%s</p>\n""" % project['texts'].description
# html blocks
if Path(item).suffix in [".html"]:
blockfile = open('%s/%s' % (project['path'], item), 'r')
code = blockfile.read()
blockfile.close()
content += code
projHtml = projHtml.format(
title=project['texts'].title,
header=headerFileTxt,
project=content,
footer=footer)
proj.write(projHtml)
proj.close()
# load templates
headerFile = open("header.html", "r")
headerFileTxt = headerFile.read()
headerFile.close()
projTem = open("templateProjectItem.html", "r")
projTemp = projTem.read()
projTem.close()
projHtmlTem = open("templateProjectHtml.html", "r")
projHtmlTemp = projHtmlTem.read()
projHtmlTem.close()
footerFile = open("footer.html", "r")
footer = footerFile.read()
footerFile.close()
# get content order
order = open('order', 'r').read().split("\n")
projects = ""
# get contents
for index, o in enumerate(order):
path = os.path.join("content", o)
if os.path.exists(path):
#print (path)
cover = glob.glob(path+"/cover*")
if cover:
cover = cover[0]
# print(cover)
# if there is no cover, skip the project!
if not cover:
continue
textsPath = os.path.join(path, "texts.py")
projectTexts = SourceFileLoader(
string.ascii_letters[index], textsPath).load_module()
content = {}
if hasattr(projectTexts, "sitecontent"):
content = projectTexts.sitecontent
project = {
"texts": projectTexts,
"cover": cover,
"path": path,
"content": content,
}
if not hasattr(projectTexts, "finished"):
generateProjectPage(project)
# make homepage items
tags = "<ol>"
for tag in projectTexts.tags.split("\n"):
tags += "<li>%s</li>" % tag
tags += "</ol>"
link = projectTexts.title.replace(" ", "") + ".html"
projectTxt = projTemp.format(
cover=cover,
link=link.lower(),
title=projectTexts.title,
tags=tags
)
projects += projectTxt
htmlFile = open("templateindex.html", "r")
htmlFileTxt = htmlFile.read()
htmlFile.close()
htmlIndex = open("index.html", "w+")
htmlIndex.write(htmlFileTxt.format(
# fontcsses=fontcsses,
header=headerFileTxt,
projects=projects,
footer=footer,
)
)
htmlIndex.close()