Skip to content

Doc: add anchormap directive for anchor redirects - #151113

Closed
StanFromIreland wants to merge 1 commit into
python:mainfrom
StanFromIreland:anchormap
Closed

Doc: add anchormap directive for anchor redirects#151113
StanFromIreland wants to merge 1 commit into
python:mainfrom
StanFromIreland:anchormap

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Jun 8, 2026

Copy link
Copy Markdown
Member

See python/docs-community#134 (and python/docs-community#58) for prior discussion and motivation. The .. anchormap:: lets us declare old-anchor: :ref:`new-target` entries, which the anchor_redirects.py extension resolves at build time and embeds as JSON in the page. A small Javascript script then redirects any achor to its new location.

To see it in action, go to: https://cpython-previews--151113.org.readthedocs.build/en/151113/using/configure.html#cmdoption-with-system-libmpdec

For that example, the extension added to using/configure.html:

<script id="python-docs-anchor-redirects" type="application/json">{"cmdoption-with-system-libmpdec": "../whatsnew/3.16.html#rem-bundled-libmpdec"}</script>
<script type="module" src="../_static/anchor_redirects.js"></script>

In this PR I only removed one entry from removed-ids.txt to serve as an example, the rest can be done in follow-ups.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33047621 | 📁 Comparing e6d0bbe against main (29a920e)

  🔍 Preview build  

1 file changed
± whatsnew/3.16.html

@encukou

encukou commented Jun 9, 2026

Copy link
Copy Markdown
Member

Sorry to be negative, but I find the automatic redirect rather confusing. Especially with your example (the mpdec option) on a big screen -- there's not much indication that the thing you were linked to is now gone.

I'm not sure this iteration is a net positive, let alone worth the maintenance cost :(

@StanFromIreland

StanFromIreland commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

Sorry to be negative, but I find the automatic redirect rather confusing. Especially with your example (the mpdec option) on a big screen -- there's not much indication that the thing you were linked to is now gone.

That's generally how redirects are implemented, although I agree it's not ideal. The rediraffe extension and the various nginx redirects we use work the same way (e.g. https://devguide.python.org/contrib/project/github.html redirects to the main index with no note). What if we added a small pop-up to notify the user of the redirect, it is done client-side so it wouldn't been terribly difficult?

I'm not sure this iteration is a net positive

I see, in any case I still think we need to do something. As it stands, the CI check is a really just a doctor who diagnoses you and walks out. ;-)

@StanFromIreland

Copy link
Copy Markdown
Member Author

I've published the Sphinx extension on PyPI as I'm looking into using it somewhere else: https://pypi.org/project/sphinx-anchormap/0.1.0/

@StanFromIreland

Copy link
Copy Markdown
Member Author

It seems this has no support, so I'm closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants