Skip to content

Commit dacd3b8

Browse files
authored
doc: add outdated warner (#1710)
1 parent ca4ab71 commit dacd3b8

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

docs/src/.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default defineConfig({
2929
head: [
3030
['link', { rel: 'icon', href: 'REPLACE_ME_DOCUMENTER_VITEPRESS_FAVICON' }],
3131
['script', {src: '/versions.js'}],
32+
['script', {src: '/warner.js'}],
3233
['script', {src: `${baseTemp.base}siteinfo.js`}]
3334
],
3435

docs/src/public/warner.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function maybeAddWarning() {
2+
// DOCUMENTER_NEWEST is defined in versions.js, DOCUMENTER_CURRENT_VERSION and DOCUMENTER_STABLE
3+
// in siteinfo.js.
4+
// If either of these are undefined something went horribly wrong, so we abort.
5+
if (
6+
window.DOCUMENTER_NEWEST === undefined ||
7+
window.DOCUMENTER_CURRENT_VERSION === undefined ||
8+
window.DOCUMENTER_STABLE === undefined
9+
) {
10+
return;
11+
}
12+
13+
// Current version is not a version number, so we can't tell if it's the newest version. Abort.
14+
if (!/v(\d+\.)*\d+/.test(window.DOCUMENTER_CURRENT_VERSION)) {
15+
return;
16+
}
17+
18+
// Current version is newest version, so no need to add a warning.
19+
if (window.DOCUMENTER_NEWEST === window.DOCUMENTER_CURRENT_VERSION) {
20+
return;
21+
}
22+
23+
// Add a noindex meta tag (unless one exists) so that search engines don't index this version of the docs.
24+
if (document.body.querySelector('meta[name="robots"]') === null) {
25+
const meta = document.createElement("meta");
26+
meta.name = "robots";
27+
meta.content = "noindex";
28+
29+
document.getElementsByTagName("head")[0].appendChild(meta);
30+
}
31+
32+
const div = document.createElement("div");
33+
div.classList.add("outdated-warning-overlay");
34+
const closer = document.createElement("button");
35+
closer.classList.add("outdated-warning-closer", "delete");
36+
closer.addEventListener("click", function () {
37+
document.body.removeChild(div);
38+
});
39+
const href = window.documenterBaseURL + "/../" + window.DOCUMENTER_STABLE;
40+
div.innerHTML =
41+
'This documentation is not for the latest stable release, but for either the development version or an older release.<br><a href="' +
42+
href +
43+
'">Click here to go to the documentation for the latest stable release.</a>';
44+
div.appendChild(closer);
45+
document.body.appendChild(div);
46+
}
47+
48+
if (document.readyState === "loading") {
49+
document.addEventListener("DOMContentLoaded", maybeAddWarning);
50+
} else {
51+
maybeAddWarning();
52+
}

0 commit comments

Comments
 (0)