Skip to content

Instantly share code, notes, and snippets.

@StevenClontz
Created December 16, 2021 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenClontz/bac32e094d0cf837872f027e3b415507 to your computer and use it in GitHub Desktop.
Save StevenClontz/bac32e094d0cf837872f027e3b415507 to your computer and use it in GitHub Desktop.
Redirecting a PreTeXt book
# FIRST, copy (not move) your HTML into the desired directory you wish to redirect to using your filesystem
# you can delete any non-HTML files at the original location, at least, only HTML can be redirected
import os
# current path to PreTeXt-generated HTML from working directory
current = os.path.join("docs")
# relative path to redirected HTML from current, default assumes move from ./docs to ./docs/archive-2021
redirect = os.path.join("archive-2021")
for filename in os.listdir(current):
if filename.endswith(".html"):
html = f'<html><head><meta http-equiv="refresh" content="0;url=./{filename}" /></head><body>Redirecting...</body></html>'
with open(os.path.join(current,filename),"w") as f:
f.write(html)
else:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment