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
|
#!/usr/bin/env python3
import html
from pathlib import Path
import tomli
EMAIL = ''.join(['&#x{:02x};'.format(ord(c)) for c in 'mailto:martin@push-f.com'])
out_dir = Path('build')
out_dir.mkdir(exist_ok=True)
html_f = open(out_dir / 'index.html', 'w')
nginx_f = open(out_dir / 'nginx_rules', 'w')
html_f.write('''<!doctype html>
<html>
<head>
<style>
body { font-family: sans; max-width: 800px; margin: 1em auto; padding: 0 1em; }
h2 { font-size: inherit; }
ul { padding-left: 1em; column-count: auto; column-width: 12rem; }
.for-purchase { color: #767676; }
</style>
<title>spec.pub</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
</head>
<body>
<h1>spec.pub</h1>
Redirects to specification publications.
<p>
Maintained by <a href="https://push-f.com/">Martin Fischer</a>.
Suggestions for new redirects <a href="%s">are welcome</a>.
</p>
Note that the redirects are lowercase (the links on this page
are capitalized for readability).
''' % EMAIL)
redirects = {}
def link(key, css_class=''):
return '<a href="/{}"{}>{}</a>'.format(
html.escape(key.lower()),
f' class={css_class}' if css_class else '',
html.escape(key))
with open('specs.toml', 'rb') as f:
data = tomli.load(f)
html_f.write('<div>')
for section, redirects in data.items():
html_f.write(f'<h2>{section}</h2>')
html_f.write('<ul>')
for key, config in sorted(redirects.items(), key=lambda t: t[0].lower()):
if isinstance(config, str):
config = {'url': config}
if not config.get('hidden'):
html_f.write('<li>')
html_f.write(link(key, css_class='for-purchase' if 'closed' in config else ''))
if 'aliases' in config:
html_f.write(
' ('
+ ', '.join([link(k) for k in config['aliases']])
+ ') '
)
html_f.write('</li>')
for path in [key, *config.get('aliases', ())]:
closed = config.get('closed')
if closed:
text = closed.replace('ISO.', 'ISO.<br><img src=/iso.svg>')
response = f"return 402 '{text}'; add_header Content-Type text/html always;"
else:
response = f'return 302 {config["url"]};'
nginx_f.write('location = /%s { %s }\n' % (path.lower(), response))
html_f.write('</ul>')
html_f.write('''
</body>
</html>''')
html_f.close()
nginx_f.close()
|