Added and fixed links in error pages
This commit is contained in:
parent
d764d3373d
commit
abe5508236
3 changed files with 37 additions and 5 deletions
|
@ -3,6 +3,8 @@ from pathlib import Path
|
||||||
from urllib import request
|
from urllib import request
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
urlroot = 'https://www.w3.org/Protocols/rfc2616'
|
||||||
|
|
||||||
src = Path('src')
|
src = Path('src')
|
||||||
root = src.joinpath('error')
|
root = src.joinpath('error')
|
||||||
with root.joinpath('root.html').open('r') as root_file:
|
with root.joinpath('root.html').open('r') as root_file:
|
||||||
|
@ -17,13 +19,13 @@ for x in error.rglob('*'):
|
||||||
if x.is_file() or x.is_symlink(): x.unlink()
|
if x.is_file() or x.is_symlink(): x.unlink()
|
||||||
|
|
||||||
req = request.Request(
|
req = request.Request(
|
||||||
'https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html',
|
f'{urlroot}/rfc2616-sec10.html',
|
||||||
method='GET')
|
method='GET')
|
||||||
|
|
||||||
with request.urlopen(req) as res:
|
with request.urlopen(req) as res:
|
||||||
raw = res.read().decode('utf-8')
|
raw = res.read().decode('utf-8')
|
||||||
|
|
||||||
codes = (re.finditer(r"(?s)<h3><a id='sec10\.[0-9]\.[0-9]+'>"
|
codes = (re.finditer(r"(?s)<h3><a id='(sec10\.[0-9]\.[0-9]+)'>"
|
||||||
r'10\.[0-9]\.[0-9]+</a>'
|
r'10\.[0-9]\.[0-9]+</a>'
|
||||||
r'\s*([0-9]+)\s([a-zA-Z\s]+)</h3>\s*<p>(.*?)</p>', raw))
|
r'\s*([0-9]+)\s([a-zA-Z\s]+)</h3>\s*<p>(.*?)</p>', raw))
|
||||||
|
|
||||||
|
@ -31,11 +33,15 @@ nginx_head = ''
|
||||||
nginx_body = ''
|
nginx_body = ''
|
||||||
|
|
||||||
for item in codes:
|
for item in codes:
|
||||||
code, title, desc = item.groups()
|
sec, code, title, desc = item.groups()
|
||||||
if int(code) < 400 or int(code) >= 600: continue
|
if int(code) < 400 or int(code) >= 600: continue
|
||||||
|
|
||||||
|
desc = re.sub(r"(<a.*?href=')(.*)('>)",
|
||||||
|
lambda x:f'{x[1]}{urlroot}/{x[2]}{x[3]}', desc)
|
||||||
|
|
||||||
with error.joinpath(f'{code}.html').open('w') as html:
|
with error.joinpath(f'{code}.html').open('w') as html:
|
||||||
content = root_html.format(
|
content = root_html.format(
|
||||||
code=code, title=title, desc=desc, style=root_css)
|
code=code, title=title, desc=desc, style=root_css, sec=sec)
|
||||||
content = re.sub(r'\s+', ' ', content)
|
content = re.sub(r'\s+', ' ', content)
|
||||||
content = re.sub(r'>\s<', '><', content)
|
content = re.sub(r'>\s<', '><', content)
|
||||||
html.write(content)
|
html.write(content)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
--gray-30: #cac5c4;
|
--gray-30: #cac5c4;
|
||||||
--gray-10: #f7f3f2;
|
--gray-10: #f7f3f2;
|
||||||
--red-40: #ff8389;
|
--red-40: #ff8389;
|
||||||
|
--blue-40: #78a9ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
@ -53,3 +54,19 @@ cite {
|
||||||
line-height: 1.125rem;
|
line-height: 1.125rem;
|
||||||
letter-spacing: .16px;
|
letter-spacing: .16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: var(--blue-40);
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
filter: brightness(1.2);
|
||||||
|
}
|
||||||
|
a:active {
|
||||||
|
filter: brightness(1.4);
|
||||||
|
}
|
||||||
|
a:focus {
|
||||||
|
color: var(--gray-100);
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,16 @@
|
||||||
<blockquote cite="https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">
|
<blockquote cite="https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">
|
||||||
{desc}
|
{desc}
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<figcaption><cite>HTTP/1.1 Status Code Definitions</cite></figcaption>
|
<figcaption><cite>
|
||||||
|
<a
|
||||||
|
href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#{sec}"
|
||||||
|
>HTTP/1.1 Status Code Definitions</a>
|
||||||
|
</cite></figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
|
<footer>
|
||||||
|
Design by edpibu,
|
||||||
|
inspired by <a href="https://www.carbondesignsystem.com/">
|
||||||
|
IBM Carbon Design System</a>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Reference in a new issue