-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanchor-build
executable file
·99 lines (77 loc) · 2.11 KB
/
anchor-build
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
#!/usr/bin/env python
import sys
import json
import os
from distutils.dir_util import copy_tree
from shutil import rmtree
configFile = open("config.json")
config = json.load(configFile)
def createBuildDir():
buildDir = os.getcwd() + "/build"
if os.path.exists(buildDir):
rmtree(buildDir)
os.mkdir(buildDir)
def writeCss():
css = """
main > * {
display: none;
}
main > *:last-child {
display: block;
}
main > *:target {
display: block;
}
main > *:target ~ * {
display: none;
}
"""
cssFile = open("build/styles/anchor-spa.css", "w+")
cssFile.write(css)
cssFile.close()
def copyAssets():
copy_tree("assets", "build/assets")
copy_tree("scripts", "build/scripts")
copy_tree("styles", "build/styles")
def writeHtml():
def loadHtmlTemplate(filename):
if filename != config['head'] and filename.split(".")[1] == 'template':
file = open("templates/" + filename)
result = """
<section class="spa-anchor" id="{id}">
{data}
</section>
""".format(id=filename.split(".")[0], data=file.read())
file.close()
return result
return ""
headTemplate = open("templates/" + config['head'])
head = headTemplate.read() + "\n<link rel=\"stylesheet\" href=\"styles/anchor-spa.css\">"
headTemplate.close()
body = ""
for (_, _, filenames) in os.walk("templates"):
for filename in filenames:
if filename != config['head']:
body += loadHtmlTemplate(filename)
body += loadHtmlTemplate(config['main'])
out = """
<!DOCTYPE html>
<html lang="{lang}">
<head>
{head}
</head>
<body>
<main>
{body}
</main>
</body>
</html>
""".format(lang=config["lang"], head=head, body=body)
outFile = open("build/index.html", "w+")
outFile.write(out)
outFile.close()
createBuildDir()
copyAssets()
writeHtml()
writeCss()
configFile.close()