-
Notifications
You must be signed in to change notification settings - Fork 55
/
build_index.py
189 lines (159 loc) · 4.26 KB
/
build_index.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python3
"""
<Program Name>
build_index.py
<Author>
Joshua Lock
<Started>
Feb 1, 2021
<Copyright>
See LICENSE-MIT for licensing information.
<Purpose>
Quick and dirty script to generate an index of published specification
versions.
Style cribbed from the bikeshed W3C theme we are using in our bikeshed
generated specification documents.
"""
import os
import sys
from subprocess import run
html_header = """<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>The Update Framework Specification</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style data-fill-with="stylesheet">
body {
counter-reset: example figure issue;
/* Layout */
max-width: 50em; /* limit line length to 50em for readability */
margin: 0 auto; /* center text within page */
padding: 1.6em 1.5em 2em 50px; /* assume 16px font size for downlevel clients */
padding: 1.6em 1.5em 2em calc(26px + 1.5em); /* leave space for status flag */
/* Typography */
line-height: 1.5;
font-family: sans-serif;
widows: 2;
orphans: 2;
word-wrap: break-word;
overflow-wrap: break-word;
hyphens: auto;
color: black;
color: var(--text);
background: white top left fixed no-repeat;
background: var(--bg) top left fixed no-repeat;
background-size: 25px auto;
}
div.head { margin-bottom: 1em; }
div.head h1 {
font-weight: bold;
margin: 0 0 .1em;
font-size: 220%;
}
p {
margin: 1em 0;
}
dd > p:first-child,
li > p:first-child {
margin-top: 0;
}
ul, ol {
margin-left: 0;
padding-left: 2em;
}
li {
margin: 0.25em 0 0.5em;
padding: 0;
}
a {
color: #034575;
color: var(--a-normal-text);
text-decoration: none;
border-bottom: 1px solid #707070;
border-bottom: 1px solid var(--a-normal-underline);
/* Need a bit of extending for it to look okay */
padding: 0 1px 0;
margin: 0 -1px 0;
}
a:visited {
color: #034575;
color: var(--a-visited-text);
border-bottom-color: #bbb;
border-bottom-color: var(--a-visited-underline);
}
a:focus,
a:hover {
background: #f8f8f8;
background: rgba(75%, 75%, 75%, .25);
background: var(--a-hover-bg);
border-bottom-width: 3px;
margin-bottom: -2px;
}
a:active {
color: #c00;
color: var(--a-active-text);
border-color: #c00;
border-color: var(--a-active-underline);
}
h1, h2, h3, h4, h5, h6, dt {
page-break-after: avoid;
page-break-inside: avoid;
font: 100% sans-serif; /* Reset all font styling to clear out UA styles */
font-family: inherit; /* Inherit the font family. */
line-height: 1.2; /* Keep wrapped headings compact */
hyphens: manual; /* Hyphenated headings look weird */
}
h2, h3, h4, h5, h6 {
margin-top: 3rem;
}
h1, h2, h3 {
color: #005A9C;
color: var(--heading-text);
}
h1 { font-size: 170%; }
h2 { font-size: 140%; }
:root {
color-scheme: light dark;
--text: black;
--bg: white;
--heading-text: #005a9c;
--a-normal-text: #034575;
--a-normal-underline: #707070;
--a-visited-text: var(--a-normal-text);
--a-visited-underline: #bbb;
--a-hover-bg: rgba(75%, 75%, 75%, .25);
--a-active-text: #c00;
--a-active-underline: #c00;
}
</style>
</head>
<body class="h-entry">
<div class="head">
<h1 id="title" class="p-name no-ref">The Update Framework Specification</h1>
</div>
<div>
<ul>
"""
html_footer = """</ul>
</body>
</html>
"""
def build_index():
html = html_header
html_locations = ['latest', 'draft']
dir_contents = sorted(os.listdir('.'), reverse=True)
for path in dir_contents:
if path.startswith('v'):
if not os.path.exists(f'{path}/index.html'):
continue
html_locations.append(path)
for loc in html_locations:
link = f" <li><a href='{loc}/index.html'>{loc}</a></li>\n"
html = html + link
html = html + html_footer
return html
if __name__ == "__main__":
html = build_index()
with open('index.html', 'w') as index:
index.write(html)