Skip to content

Commit

Permalink
redirect old build/html/ links to correct location
Browse files Browse the repository at this point in the history
  • Loading branch information
remrama committed Jan 31, 2025
1 parent 8778b0e commit 55955e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
38 changes: 26 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"numpydoc", # Generates numPy style docstrings (Needs to be loaded *after* autodoc)
"sphinx_copybutton", # Adds copy-to-clipboard button in code blocks
"sphinx_design", # Adds directives for badges, dropdowns, tabs, etc
"sphinx_reredirects", # Generates redirects for moved pages

]

Expand Down Expand Up @@ -684,18 +685,9 @@
"title": "Page not found",
"body": """
<h1>This page may have moved.</h1>
<p>
The YASA documentation site has recently been upgraded!
Some URLs have changed.
</p>
<p>
Browse the <bold>Navigation menu</bold> or use the
<bold>Search button</bold> to find the page you were looking for.
</p>
<p>
Please update the URLs of any bookmarks or autofills in your
browser that point to the YASA documentation site.
</p>
<p>The YASA documentation site has recently been upgraded! Some URLs have changed.</p>
<p>Navigate the menu or search to find the page you were looking for.</p>
<p>Please update any bookmarks or autofills that point to the YASA documentation site.</p>
""",
}

Expand All @@ -704,3 +696,25 @@
# Note special case when using default GitHub pages URL: "/<repo>/"
# https://sphinx-notfound-page.readthedocs.io/en/latest/faq.html#does-this-extension-work-with-github-pages
notfound_urls_prefix = "/yasa/"

# -- External extensions -----------------------------------------------------
# -- -> Options for sphinx_reredirects -------------------------------------------------
# https://documatt.com/sphinx-reredirects/usage.html
# Defaults to {}
redirects = {}

# TEMPORARY: This can be removed after people stop using old links.
# We need to generate a list of redirects for the old documentation
# that was hosted under relative paths behind buid/html.
# Create a sphinx extension that will find all docs and generate a
# redirects dictionary that maps build/html/docpath to just docpath.
def setup(app):
app.connect("env-updated", generate_redirects)

def generate_redirects(app, env):
redirects = app.config.redirects or {}
for docpath in env.found_docs:
old_path = f"build/html/{docpath}"
new_path = "../" * old_path.count("/") + f"{docpath}.html"
redirects[old_path] = new_path
app.config.redirects = redirects
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ docs = [
"sphinx-design>=0.6",
"sphinx-copybutton>=0.5",
"sphinx-notfound-page>=1",
"sphinx-reredirects>=0.1",
"pydata-sphinx-theme>0.16",
"numpydoc>=1.8",
]
Expand Down

0 comments on commit 55955e5

Please sign in to comment.