Skip to content

Commit 5d0c1cf

Browse files
committed
Out-of-date version banner
1 parent 2a247ba commit 5d0c1cf

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

docs/extra.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,19 @@ div.doc-contents {
4646
.highlight.no-copy .md-clipboard {
4747
display: none;
4848
}
49+
50+
/* Old Docs Banner */
51+
div[data-md-component=announce] {
52+
background-color: rgba(255,145,0,.1);
53+
}
54+
div[data-md-component=announce]>div#announce-msg{
55+
color: var(--md-admonition-fg-color);
56+
font-size: .8rem;
57+
text-align: center;
58+
margin: 15px;
59+
}
60+
div[data-md-component=announce]>div#announce-msg>a{
61+
color: var(--md-typeset-a-color);
62+
text-decoration: underline;
63+
}
64+

docs/extra.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Show warning banner when displaying old content versions
2+
window.addEventListener("DOMContentLoaded", function() {
3+
var xhr = new XMLHttpRequest();
4+
xhr.open("GET", "/versions.json");
5+
xhr.onload = function() {
6+
var versions = JSON.parse(this.responseText);
7+
latest_version = ""
8+
for (id in versions) {
9+
if (versions[id]["aliases"].length > 0 && versions[id]["aliases"].includes("latest")) {
10+
latest_version = "/" + versions[id].version + "/";
11+
}
12+
}
13+
if (!window.location.pathname.includes("/latest/") && (latest_version.length > 0 && !window.location.pathname.includes(latest_version))) {
14+
document.querySelector("div[data-md-component=announce]").innerHTML = "<div id='announce-msg'>This documentation is for a previous version. We recommend you <a href='/latest/'>use the latest</a>.</div>";
15+
}
16+
};
17+
xhr.send();
18+
});
19+

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ theme:
2626

2727
extra_css:
2828
- extra.css
29+
extra_javascript:
30+
- extra.js
2931

3032
markdown_extensions:
3133
- pymdownx.highlight

0 commit comments

Comments
 (0)