Skip to content

Commit 58157c7

Browse files
committed
Rewritten functions using ES6 style
1 parent 19d982d commit 58157c7

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed
Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
(function() {
2-
const links = document.getElementsByTagName('a');
3-
for (let i = 0; i < links.length; i++) {
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) => {
413
const re = /(whatsnew.html)#(whatsnew)-[\d]+(-\w+)+/g;
5-
let linkElements = links[i].href.split("/");
14+
let linkElements = link.href.split("/");
615
if (re.test(linkElements.slice(-1)[0])) {
716
let whatsNew = linkElements.slice(-1)[0].split("#");
817
whatsNew = generateWhatsNew(whatsNew);
918
linkElements[linkElements.length - 1] = whatsNew;
10-
links[i].href = linkElements.join("/")
19+
link.href = linkElements.join("/")
1120
}
12-
}
13-
/* Reformats last part of 'whatsnew' URLs */
14-
function generateWhatsNew(whatsNew) {
15-
let url = whatsNew[0];
16-
let anchor = whatsNew[1];
17-
url = replaceURL(url);
18-
let anchorEls = anchor.slice(9).split("-");
19-
anchorEls[0] = reformatVersion(anchorEls[0]);
20-
return url + anchorEls[0] + anchorEls.slice(1).join("-");
21-
}
22-
23-
/* Replaces 'whatsnew.html' with 'whatsnew/' */
24-
function replaceURL(url) {
25-
return url.split(".")[0] + "/"
26-
}
27-
28-
/* Converts version number into vX.X.X */
29-
function reformatVersion(version) {
30-
return "v" + version.slice(0,1) + "." + version.slice(1,-1) + "." + version.slice(-1) + ".html#"
31-
}
32-
})();
21+
});
22+
})();

doc/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,4 @@ def setup(app):
657657
app.add_autodocumenter(AccessorMethodDocumenter)
658658
app.add_autodocumenter(AccessorCallableDocumenter)
659659
app.add_directive('autosummary', PandasAutosummary)
660+
app.add_js('js/whatsnew_links.js')

doc/source/themes/nature_with_gtoc/layout.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,4 @@ <h3 style="margin-top: 1.5em;">{{ _('Search') }}</h3>
105105
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
106106
})();
107107
</script>
108-
<script type="text/javascript" src="./_static/js/whatsnew_links.js"></script>
109108
{% endblock %}

0 commit comments

Comments
 (0)