Add unicode-input docs redirect

This commit is contained in:
pagedown 2021-12-10 17:34:39 +08:00
parent 7e449dec4f
commit 5956639082
No known key found for this signature in database
GPG Key ID: E921CF18AC8FF6EB

View File

@ -79,16 +79,9 @@ def run_html(args: Any) -> None:
add_old_redirects('docs/_build/dirhtml') add_old_redirects('docs/_build/dirhtml')
def add_old_redirects(loc: str) -> None: def generate_redirect_html(link_name: str, bname: str) -> None:
for dirpath, dirnames, filenames in os.walk(loc): with open(link_name, 'w') as f:
if dirpath != loc: f.write(f'''
for fname in filenames:
if fname == 'index.html':
bname = os.path.basename(dirpath)
base = os.path.dirname(dirpath)
link_name = os.path.join(base, f'{bname}.html') if base else f'{bname}.html'
with open(link_name, 'w') as f:
f.write(f'''
<html> <html>
<head> <head>
<title>Redirecting...</title> <title>Redirecting...</title>
@ -107,6 +100,19 @@ window.location.replace('./{bname}/' + window.location.hash);
''') ''')
def add_old_redirects(loc: str) -> None:
for dirpath, dirnames, filenames in os.walk(loc):
if dirpath != loc:
for fname in filenames:
if fname == 'index.html':
bname = os.path.basename(dirpath)
base = os.path.dirname(dirpath)
link_name = os.path.join(base, f'{bname}.html') if base else f'{bname}.html'
generate_redirect_html(link_name, bname)
generate_redirect_html(os.path.join(loc, 'kittens', 'unicode-input.html'), 'unicode_input')
def run_docs(args: Any) -> None: def run_docs(args: Any) -> None:
subprocess.check_call(['make', 'docs']) subprocess.check_call(['make', 'docs'])