Skip to content

Commit 81135c0

Browse files
committed
update the url when no version is specified.
It doesn't update a link if it is external, or if the target is not a document in the documentation.
1 parent 5a308ac commit 81135c0

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

_includes/footer.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,41 @@
4545
anchors.add(selector);
4646
</script>
4747
<script>
48+
if (typeof String.prototype.endsWith !== "function") {
49+
String.prototype.endsWith = function(suffix) {
50+
return this.indexOf(suffix, this.length - suffix.length) !== -1;
51+
};
52+
}
53+
54+
// Triggered when changing the version from select box..
4855
function changeVersion() {
4956
var e = document.getElementById("version");
5057
var strVersion = e.options[e.selectedIndex].value;
5158
window.location = "{{ site.url }}/" + strVersion + "/";
5259
}
60+
61+
// Update the URL if the version is not specified..
62+
var links = document.links;
63+
64+
for(var i = 0; i < links.length; i++) {
65+
var link = links[i].href;
66+
67+
// Make sure the link is not external and targets a document in the documentation..
68+
if (link.indexOf("{{ site.url }}") === 0 && link.endsWith(".html")) {
69+
var url = link.substring(0, link.lastIndexOf("/") + 1);
70+
var file = link.split("/").pop();
71+
var parts = url.split("/");
72+
73+
// No version specified in the URL..
74+
if (/^v(\d+\.)?(\d+\.)?(\*|\d+)$/.test(parts[parts.length-2]) === false) {
75+
var e = document.getElementById("version");
76+
var strUser = e.options[e.selectedIndex].value;
77+
links[i].href = url + strUser + "/" + file;
78+
}
79+
}
80+
}
81+
82+
// Some random quotes that appears in the bottom of the page..
5383
var quotes = [
5484
"The best thing about a boolean is even if you are wrong, you are only off by a bit.",
5585
"There are two ways to write error-free programs; only the third one works.",

_posts/v0.0.29/2016-01-01-index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This module currently support [Node.js 4.x](https://nodejs.org/en/download/) and
1717

1818
#### Node.js
1919

20-
Install with npm and jump to the [configuration page](./Configuration.md) to get started.
20+
Install with npm and jump to the [configuration page](./Configuration.html) to get started.
2121

2222
~~~ bash
2323
npm install tmi.js --save

_posts/v1.0.0/2016-01-01-index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This module currently support [Node.js 4.x](https://nodejs.org/en/download/) and
1717

1818
#### Node.js
1919

20-
Install with npm and jump to the [configuration page](./Configuration.md) to get started.
20+
Install with npm and jump to the [configuration page](./Configuration.html) to get started.
2121

2222
~~~ bash
2323
npm install tmi.js --save

0 commit comments

Comments
 (0)