Pandas: DOC: Redirect old whatsnew links

Created on 14 Nov 2018  路  7Comments  路  Source: pandas-dev/pandas

In https://github.com/pandas-dev/pandas/pull/21599 we're chagning the structure of our whatsnew. Previously the whatsnew for each version was concatenated into a single large file.

Consider a link to the anchor #whatsnew-0190-enhancements-other. There are three cases:

  1. Version-specific URLs like http://pandas.pydata.org/pandas-docs/version/0.23.0/whatsnew.html#whatsnew-0190-enhancements-other will continue to work. We don't have to change anything.
  2. People linking via /stable (which is probably more common), or to version 0.24.0 or higher will break. http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#whatsnew-0190-enhancements-other won't be a valid reference. We would need to rewrite it to http://pandas.pydata.org/pandas-docs/stable/releases/#whatsnew-0190-enhancements-other

We use nginx for our webserver at pandas.pydata.org. But AFAICT, we can't use a rewrite rule to redirect this links, since nginx doesn't see the anchor.

We should be able to detect this in Javascript. When we're on the whatsnew for 0.24.0 or greater, we want to look for anchors pointing to /whatsnew.html#whatsnew-<version> for 0.23.4 or older. Then we'd rewrite /whatsnew.html#whatsnew-<version>-<title> to /whatsnew/<version>.html#<title>. So a test case is

before: http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#whatsnew-0190-enhancements-other
after:  http://pandas.pydata.org/pandas-docs/stable/whatsnew/v0.19.0.html#other-enhancements
Docs

All 7 comments

I can write a script for this, but where exactly are the HTML template files defined, from which the script can be called? Or do you just want the code?

Thanks. I think in doc/source/themes/nature_with_gtoc/. Right now we hardcode JS in layout.html. You could maybe split that out to a _static/ directory and load it if you want.

I've written a script to replace the URL links, which makes some assumptions:

  • The version needs to be converted from '0190' to 'v0.19.0' every time, and there are always written as 1 digit, 2 digits, 1 digit?
  • The version number is always separated from the text by a dash '-'

If these assumptions are correct, I can make the PR. Since this PR includes no changes to Python code, are running / passing the tests necessary?

Also, is there any page with many such links to test it on?

https://github.com/ismailuddin/pandas/commit/1f3fabed2a3b6e53b3a0cbb92a2ae01c2821ad63

Thanks.

The 0190 comes from the filename, which didn't change (aside from .txt to .rst). It should always be 1 digit, 1 or 2 digits, 1 digit (1 or 2 for the middle since we have 0.4.x through 0.9.x).

The "version number" for your second bullet is hand-written.

$ ag '_whatsnew_\d+:' | sort | uniq

doc/source/whatsnew/v0.10.0.txt:1:.. _whatsnew_0100:
doc/source/whatsnew/v0.10.1.txt:1:.. _whatsnew_0101:
doc/source/whatsnew/v0.11.0.txt:1:.. _whatsnew_0110:
doc/source/whatsnew/v0.12.0.txt:1:.. _whatsnew_0120:
doc/source/whatsnew/v0.13.0.txt:1:.. _whatsnew_0130:
doc/source/whatsnew/v0.13.1.txt:1:.. _whatsnew_0131:
doc/source/whatsnew/v0.14.0.txt:1:.. _whatsnew_0140:
doc/source/whatsnew/v0.14.1.txt:1:.. _whatsnew_0141:
doc/source/whatsnew/v0.15.0.txt:1:.. _whatsnew_0150:
doc/source/whatsnew/v0.15.1.txt:1:.. _whatsnew_0151:
doc/source/whatsnew/v0.15.2.txt:1:.. _whatsnew_0152:
doc/source/whatsnew/v0.16.0.txt:1:.. _whatsnew_0160:
doc/source/whatsnew/v0.16.1.txt:1:.. _whatsnew_0161:
doc/source/whatsnew/v0.16.2.txt:1:.. _whatsnew_0162:
doc/source/whatsnew/v0.17.0.txt:1:.. _whatsnew_0170:
doc/source/whatsnew/v0.17.1.txt:1:.. _whatsnew_0171:
doc/source/whatsnew/v0.18.0.txt:1:.. _whatsnew_0180:
doc/source/whatsnew/v0.18.1.txt:1:.. _whatsnew_0181:
doc/source/whatsnew/v0.19.0.txt:1:.. _whatsnew_0190:
doc/source/whatsnew/v0.19.1.txt:1:.. _whatsnew_0191:
doc/source/whatsnew/v0.19.2.txt:1:.. _whatsnew_0192:
doc/source/whatsnew/v0.20.0.txt:1:.. _whatsnew_0200:
doc/source/whatsnew/v0.20.2.txt:1:.. _whatsnew_0202:
doc/source/whatsnew/v0.20.3.txt:1:.. _whatsnew_0203:
doc/source/whatsnew/v0.21.0.txt:1:.. _whatsnew_0210:
doc/source/whatsnew/v0.21.1.txt:1:.. _whatsnew_0211:
doc/source/whatsnew/v0.22.0.txt:1:.. _whatsnew_0220:
doc/source/whatsnew/v0.23.0.txt:1:.. _whatsnew_0230:
doc/source/whatsnew/v0.23.1.txt:1:.. _whatsnew_0231:
doc/source/whatsnew/v0.23.2.txt:1:.. _whatsnew_0232:
doc/source/whatsnew/v0.23.3.txt:1:.. _whatsnew_0233:
doc/source/whatsnew/v0.23.4.txt:1:.. _whatsnew_0234:
doc/source/whatsnew/v0.23.5.txt:1:.. _whatsnew_0235:
doc/source/whatsnew/v0.24.0.txt:1:.. _whatsnew_0240:
doc/source/whatsnew/v0.5.0.txt:2:.. _whatsnew_050:
doc/source/whatsnew/v0.6.0.txt:1:.. _whatsnew_060:
doc/source/whatsnew/v0.6.1.txt:2:.. _whatsnew_061:
doc/source/whatsnew/v0.7.0.txt:1:.. _whatsnew_0700:
doc/source/whatsnew/v0.7.1.txt:1:.. _whatsnew_0701:
doc/source/whatsnew/v0.7.2.txt:1:.. _whatsnew_0702:
doc/source/whatsnew/v0.7.3.txt:1:.. _whatsnew_0703:
doc/source/whatsnew/v0.8.0.txt:1:.. _whatsnew_080:
doc/source/whatsnew/v0.8.1.txt:1:.. _whatsnew_0801:
doc/source/whatsnew/v0.9.0.txt:1:.. _whatsnew_0900:
doc/source/whatsnew/v0.9.1.txt:1:.. _whatsnew_0901:

Some inconsistencies. 060 vs. 0700.

https://github.com/pandas-dev/pandas/pull/21599 will hopefully be merged soon. If not, you can apply your changes on top of it to check the actual URLs.

Ok so this update should deal with the variable version numbers, so reformatting links to either v0.6.0 or v0.24.0.

About #21599 , how would you like me to proceed?

https://github.com/ismailuddin/pandas/commit/8f35b4fa0393c370d5fa3a316421a40a4194cba8

Just merged it into master, so you you merge that then you're good to go.

FYI, the doc build will be live in ~1 hour, whenever https://travis-ci.org/pandas-dev/pandas/jobs/455198927 finishes. Those will be uploaded to http://pandas-docs.github.io/pandas-docs-travis/ (you don't have to worry about redirecting anything on that domain)

Thanks for this! A redirect map with a hook for parsing uri fragments could be a useful addition to Sphinx, as well.

You can add custom JavaScript to Sphinx templates with add_js_file() (was: add_javascript()) in conf.py.

https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_js_file

https://docs.readthedocs.io/en/latest/guides/adding-custom-css.html#adding-custom-css-or-javascript-to-a-sphinx-project

Was this page helpful?
0 / 5 - 0 ratings