diff --git a/doc/source/_static/js/whatsnew_links.js b/doc/source/_static/js/whatsnew_links.js new file mode 100644 index 0000000000000..bbe7d531a687d --- /dev/null +++ b/doc/source/_static/js/whatsnew_links.js @@ -0,0 +1,22 @@ +(function() { + /* Reformats last part of 'whatsnew' URLs */ + const generateWhatsNew = (whatsNew) => { + let url = whatsNew[0], anchor = whatsNew[1]; + url = ((url) => url.split(".")[0] + "/")(url); + let anchorEls = anchor.slice(9).split("-"); + anchorEls[0] = ((version) => "v" + version.slice(0,1) + "." + version.slice(1,-1) + "." + version.slice(-1) + ".html#")(anchorEls[0]); + return url + anchorEls[0] + anchorEls.slice(1).join("-"); + } + + const links = Array.from(document.getElementsByTagName("a")); + links.forEach((link) => { + const re = /(whatsnew.html)#(whatsnew)-[\d]+(-\w+)+/g; + let linkElements = link.href.split("/"); + if (re.test(linkElements.slice(-1)[0])) { + let whatsNew = linkElements.slice(-1)[0].split("#"); + whatsNew = generateWhatsNew(whatsNew); + linkElements[linkElements.length - 1] = whatsNew; + link.href = linkElements.join("/"); + } + }); +})(); diff --git a/doc/source/conf.py b/doc/source/conf.py index 47adc80204fcc..869e80dda752a 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -698,3 +698,4 @@ def setup(app): app.add_autodocumenter(AccessorMethodDocumenter) app.add_autodocumenter(AccessorCallableDocumenter) app.add_directive('autosummary', PandasAutosummary) + app.add_js_file('js/whatsnew_links.js')