-
Notifications
You must be signed in to change notification settings - Fork 11
/
rebuild.py
75 lines (56 loc) · 1.83 KB
/
rebuild.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
'''
This script copies and templates the index.html for the various classless frameworks.
Check out http://cssbed.com for more info.
'''
import os
list_marker = '<!-- options -->'
snippet_marker = "<link rel='stylesheet' href='https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.css'>"
name_marker = 'CSS Bed'
snippet_fn = 'snippet.txt'
link_fn = 'link.txt'
reset_fn = 'reset.css'
index_fn = 'index.html'
source_marker = "https://github.com/ubershmekel/cssbed"
'''
<ul>
<li><a href="/water.css/">Water.css</a></li>
</ul>
'''
base = open(index_fn).read()
def fix_options(html):
parts = html.split(list_marker)
return parts[0] + list_marker + themes_list_html + list_marker + parts[2]
def render(path):
print("path " + path)
html = base
snippet_path = os.path.join(path, snippet_fn)
link_path = os.path.join(path, link_fn)
#reset_path = os.path.join(path, reset_fn)
if os.path.exists(snippet_path):
snippet = open(snippet_path).read()
html = html.replace(snippet_marker, snippet)
link = open(link_path).read()
html = html.replace(source_marker, link)
html = html.replace(name_marker, path)
html = fix_options(html)
target = os.path.join(path, index_fn)
open(target, 'w').write(html)
def get_themes():
for fn in os.listdir('.'):
if os.path.isdir(fn) and not fn.startswith('.'):
yield fn
themes = sorted(list(get_themes()))
print(themes)
themes_list_html = '\n <ul>\n'
for theme in themes:
themes_list_html += ' <li><a href="/' + theme + '">' + theme + '</a>\n'
themes_list_html += ' </ul>\n'
print(themes_list_html)
for theme in themes:
print("rendering " + theme)
render(theme)
# Mainly render the root to update the theme list.
# Also, this is kind of recursive in a trippy way.
html = open(index_fn).read()
open(index_fn, 'w').write(fix_options(html))