diff --git a/generate_errors.py b/generate_errors.py index a6101e8..1036ce4 100644 --- a/generate_errors.py +++ b/generate_errors.py @@ -3,6 +3,8 @@ from pathlib import Path from urllib import request import re +urlroot = 'https://www.w3.org/Protocols/rfc2616' + src = Path('src') root = src.joinpath('error') 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() req = request.Request( - 'https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html', + f'{urlroot}/rfc2616-sec10.html', method='GET') with request.urlopen(req) as res: raw = res.read().decode('utf-8') -codes = (re.finditer(r"(?s)

" +codes = (re.finditer(r"(?s)

" r'10\.[0-9]\.[0-9]+' r'\s*([0-9]+)\s([a-zA-Z\s]+)

\s*

(.*?)

', raw)) @@ -31,11 +33,15 @@ nginx_head = '' nginx_body = '' for item in codes: - code, title, desc = item.groups() + sec, code, title, desc = item.groups() if int(code) < 400 or int(code) >= 600: continue + + desc = re.sub(r"()", + lambda x:f'{x[1]}{urlroot}/{x[2]}{x[3]}', desc) + with error.joinpath(f'{code}.html').open('w') as html: 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) html.write(content) diff --git a/src/error/root.css b/src/error/root.css index 779c4aa..1a4dfec 100644 --- a/src/error/root.css +++ b/src/error/root.css @@ -6,6 +6,7 @@ --gray-30: #cac5c4; --gray-10: #f7f3f2; --red-40: #ff8389; + --blue-40: #78a9ff; } body { @@ -53,3 +54,19 @@ cite { line-height: 1.125rem; 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; +} diff --git a/src/error/root.html b/src/error/root.html index a1ddf9b..f012ba6 100644 --- a/src/error/root.html +++ b/src/error/root.html @@ -25,7 +25,16 @@
{desc}
-
HTTP/1.1 Status Code Definitions
+
+ HTTP/1.1 Status Code Definitions +
+