Debian Codegraph @

book/version.js

raw symbols SCIP
1 // Version banner + landing-page tile highlighting.
2 //
3 // The site hosts several channels under one domain:
4 // / latest stable release (a copy of the newest /<version>/)
5 // /master/ development docs, rebuilt on every push to master
6 // /<version>/ archived release snapshots
7 //
8 // CI deploys the same built HTML to each folder, so the channel can only
9 // be told apart at runtime from the URL path.
10 (function () {
11 "use strict";
12
13 var segments = window.location.pathname.split("/").filter(Boolean);
14 var first = segments[0];
15
16 var channel;
17 if (first === "master") {
18 channel = { kind: "nightly" };
19 } else if (/^\d+\.\d+/.test(first || "")) {
20 channel = { kind: "version", version: first };
21 } else {
22 channel = { kind: "stable" };
23 }
24
25 if (channel.kind === "nightly" || channel.kind === "version") {
26 var releasePath = "/" + segments.slice(1).join("/");
27
28 var banner = document.createElement("div");
29 banner.id = "helix-version-banner";
30 banner.setAttribute("role", "status");
31
32 var link =
33 '<a href="' + releasePath + '">View this page in the latest release &rarr;</a>';
34 if (channel.kind === "nightly") {
35 banner.className = "nightly";
36 banner.innerHTML =
37 "You're reading the <strong>development (master)</strong> docs &mdash; " +
38 "they describe unreleased changes. " + link;
39 } else {
40 banner.className = "archived";
41 banner.innerHTML =
42 "You're reading the docs for <strong>" + channel.version +
43 "</strong>, which may be outdated. " + link;
44 }
45
46 var main = document.querySelector("#mdbook-content main") || document.body;
47 main.insertBefore(banner, main.firstChild);
48 }
49
50 // Landing-page chooser
51 var currentHref = channel.kind === "nightly" ? "/master/" : "/";
52 var tiles = document.querySelectorAll(".version-tiles .version-tile");
53 for (var i = 0; i < tiles.length; i++) {
54 if (tiles[i].getAttribute("href") === currentHref) {
55 tiles[i].classList.add("current");
56 }
57 }
58 })();