From 7c1b8197286556c9554cd39a2bd34f7cbd381d76 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 17 Jul 2021 09:59:46 +0530 Subject: [PATCH] Use nicer URLs without .html suffix on website Also easier insertion of analytics tag for the website without needing a custom template. The old .html URLs are redirected via meta http-equiv refresh, which is all gh-pages supports --- docs/Makefile | 2 +- docs/_templates/layout.html | 6 ----- publish.py | 49 +++++++++++++++++++------------------ 3 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 docs/_templates/layout.html diff --git a/docs/Makefile b/docs/Makefile index 2e07b0139..5f857fa19 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -2,7 +2,7 @@ # # You can set these variables from the command line. -SPHINXOPTS = -j auto -T $(FAIL_WARN) +SPHINXOPTS = -j auto -T $(FAIL_WARN) $(OPTS) SPHINXBUILD = sphinx-build SPHINXPROJ = kitty SOURCEDIR = . diff --git a/docs/_templates/layout.html b/docs/_templates/layout.html deleted file mode 100644 index e5b482464..000000000 --- a/docs/_templates/layout.html +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "!layout.html" %} - -{%- block extrahead %} - - {{ super() }} -{% endblock %} diff --git a/publish.py b/publish.py index 60ca3a562..5dbd27a3c 100755 --- a/publish.py +++ b/publish.py @@ -63,29 +63,31 @@ def run_man(args: Any) -> None: def run_html(args: Any) -> None: - call('make FAIL_WARN=-W html', cwd=docs_dir) + call('make FAIL_WARN=-W "OPTS=-D html_theme_options.analytics_id=UA-20736318-2" dirhtml', cwd=docs_dir) + add_old_redirects('docs/_build/dirhtml') -def add_analytics() -> None: - analytics = ''' - - - -''' - for dirpath, firnames, filenames in os.walk(publish_dir): - for fname in filenames: - if fname.endswith('.html'): - with open(os.path.join(dirpath, fname), 'r+b') as f: - html = f.read().decode('utf-8') - html = html.replace('', analytics, 1) - f.seek(0), f.truncate() - f.write(html.encode('utf-8')) +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' + with open(link_name, 'w') as f: + f.write(f''' + + +Redirecting... + + + + +

Redirecting, please wait...

+ + +''') def run_docs(args: Any) -> None: @@ -95,8 +97,7 @@ def run_docs(args: Any) -> None: def run_website(args: Any) -> None: if os.path.exists(publish_dir): shutil.rmtree(publish_dir) - shutil.copytree(os.path.join(docs_dir, '_build', 'html'), publish_dir) - add_analytics() + shutil.copytree(os.path.join(docs_dir, '_build', 'dirhtml'), publish_dir, symlinks=True) with open(os.path.join(publish_dir, 'current-version.txt'), 'w') as f: f.write(version) shutil.copy2(os.path.join(docs_dir, 'installer.sh'), publish_dir) @@ -408,7 +409,7 @@ def main() -> None: if ans.lower() != 'y': return if actions == ['website']: - actions.insert(0, 'docs') + actions.insert(0, 'html') for action in actions: print('Running', action) cwd = os.getcwd()