Skip to content

Commit 01f5905

Browse files
committed
Add JS function to reformat 'Whats New' links for new format
1 parent c55057f commit 01f5905

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Diff for: doc/source/_static/js/whatsnew_links.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(function() {
2+
/* Reformats last part of 'whatsnew' URLs */
3+
const generateWhatsNew = (whatsNew) => {
4+
let url = whatsNew[0], anchor = whatsNew[1];
5+
url = ((url) => url.split(".")[0] + "/")(url);
6+
let anchorEls = anchor.slice(9).split("-");
7+
anchorEls[0] = ((version) => "v" + version.slice(0,1) + "." + version.slice(1,-1) + "." + version.slice(-1) + ".html#")(anchorEls[0]);
8+
return url + anchorEls[0] + anchorEls.slice(1).join("-");
9+
}
10+
11+
const links = Array.from(document.getElementsByTagName("a"));
12+
links.forEach((link) => {
13+
const re = /(whatsnew.html)#(whatsnew)-[\d]+(-\w+)+/g;
14+
let linkElements = link.href.split("/");
15+
if (re.test(linkElements.slice(-1)[0])) {
16+
let whatsNew = linkElements.slice(-1)[0].split("#");
17+
whatsNew = generateWhatsNew(whatsNew);
18+
linkElements[linkElements.length - 1] = whatsNew;
19+
link.href = linkElements.join("/")
20+
}
21+
});
22+
})();

Diff for: doc/source/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -698,3 +698,4 @@ def setup(app):
698698
app.add_autodocumenter(AccessorMethodDocumenter)
699699
app.add_autodocumenter(AccessorCallableDocumenter)
700700
app.add_directive('autosummary', PandasAutosummary)
701+
app.add_js('js/whatsnew_links.js')

0 commit comments

Comments
 (0)