Skip to content

Commit 1f3fabe

Browse files
committed
Added JS file
1 parent e73337d commit 1f3fabe

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(function() {
2+
const links = document.getElementsByTagName('a');
3+
for (let i = 0; i < links.length; i++) {
4+
let linkElements = links[i].href.split("/");
5+
var re = /(whatsnew.html)#(whatsnew)-[A-Za-z\d]+(-\w+)+/g;
6+
if (re.test(linkElements.slice(-1)[0])) {
7+
let whatsNew = linkElements.slice(-1)[0].split("#");
8+
whatsNew = generateWhatsNew(whatsNew);
9+
linkElements[linkElements.length - 1] = whatsNew;
10+
links[i].href = linkElements.join("/")
11+
}
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,3) + "." + version.slice(3) + ".html#"
31+
}
32+
})();

0 commit comments

Comments
 (0)