diff --git a/common.yaml b/common.yaml index ac58d7db..d0b668a6 100644 --- a/common.yaml +++ b/common.yaml @@ -11,6 +11,10 @@ colors: light: "#FF5788" dark: "#FB326E" +banner: + content: "You are viewing an older version of the docs. See the [latest version](https://docs.siderolabs.com/talos/latest)." + dismissible: false + favicon: "/images/favicon.svg" contextual: diff --git a/public/banner.js b/public/banner.js new file mode 100644 index 00000000..52f0dfbe --- /dev/null +++ b/public/banner.js @@ -0,0 +1,52 @@ +(function () { + function shouldCheckPath() { + const path = window.location.pathname; + + return ( + path.startsWith("/omni/") || + path.startsWith("/kubernetes-guides/") || + path.startsWith("/talos/v1.12/") + ); + } + + function deleteVersionBannerIfNeeded() { + if (!shouldCheckPath()) return; + + const banner = document.getElementById("banner"); + if (!banner) return; + + const isVersionBanner = + banner.textContent && + banner.textContent.includes( + "You are viewing an older version of the docs." + ); + + if (isVersionBanner) { + banner.remove(); + } + } + + deleteVersionBannerIfNeeded(); + + // Run after hydration + window.addEventListener("load", deleteVersionBannerIfNeeded); + + // Handle SPA navigation (Next.js) + const pushState = history.pushState; + history.pushState = function () { + pushState.apply(this, arguments); + setTimeout(deleteVersionBannerIfNeeded, 0); + }; + + window.addEventListener("popstate", () => { + setTimeout(deleteVersionBannerIfNeeded, 0); + }); + + // Watch for React re-mounting the banner + const observer = new MutationObserver(deleteVersionBannerIfNeeded); + observer.observe(document.body, { + childList: true, + subtree: true, + }); +})(); + diff --git a/public/docs.json b/public/docs.json index 4f04301e..e10b065d 100644 --- a/public/docs.json +++ b/public/docs.json @@ -8,6 +8,10 @@ "dark": "#FB326E" }, "favicon": "/images/favicon.svg", + "banner": { + "content": "You are viewing an older version of the docs. See the [latest version](https://docs.siderolabs.com/talos/latest).", + "dismissible": false + }, "contextual": { "options": [ "copy",