forked from iancoleman/bip39
-
Notifications
You must be signed in to change notification settings - Fork 26
/
compile.py
53 lines (39 loc) · 1.51 KB
/
compile.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
import os
import re
import datetime
from io import open
# This script generates the bip39-standalone.html file.
# It removes script and style tags and replaces with the file content.
def compile(sourcefile):
f = open(os.path.join("src", sourcefile), "r", encoding="utf-8")
page = f.read()
f.close()
# Script tags
scriptsFinder = re.compile("""<script src="(.*)"></script>""")
scripts = scriptsFinder.findall(page)
for script in scripts:
filename = os.path.join("src", script)
s = open(filename, "r", encoding="utf-8")
scriptContent = "<script>%s</script>" % s.read()
s.close()
scriptTag = """<script src="%s"></script>""" % script
page = page.replace(scriptTag, scriptContent)
# Style tags
stylesFinder = re.compile("""<link rel="stylesheet" href="(.*)" />""")
styles = stylesFinder.findall(page)
for style in styles:
filename = os.path.join("src", style)
s = open(filename, "r", encoding="utf-8")
print("Writing " + filename + " into html")
styleContent = "<style>%s</style>" % s.read()
s.close()
styleTag = """<link rel="stylesheet" href="%s" />""" % style
page = page.replace(styleTag, styleContent)
# Write the standalone file
f = open(sourcefile, 'w', encoding="utf-8")
f.write(page)
f.close()
print(str(datetime.datetime.now()) + " - DONE Compiled: " + sourcefile)
filenames = ['index.html', 'index-zh.html']
for filename in filenames:
compile(filename)