From de3f450286a49dc6f27c92518e4778b0a2ab32a0 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Thu, 16 Jun 2022 00:51:37 +0100 Subject: [PATCH 1/2] Quick hacky version dropdown --- config.toml | 3 ++ layouts/partials/hooks/body-end.html | 1 + layouts/partials/navbar.html | 44 +++++++++++++++++++++------- static/js/version_selector.js | 32 ++++++++++++++++++++ 4 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 static/js/version_selector.js diff --git a/config.toml b/config.toml index eabc50e2..15816601 100644 --- a/config.toml +++ b/config.toml @@ -52,6 +52,9 @@ current_version_url = "https://spec.matrix.org/latest" #major = "1" #minor = "2" #release_date = "February 02, 2022" +# Released versions to show in the version dropdown. Th template will also include a "historical" entry, +# and (if the status above is "stable") an "unstable" entry. +history = [ "unstable", "v1.2", "v1.1", "historical" ] # User interface configuration [params.ui] diff --git a/layouts/partials/hooks/body-end.html b/layouts/partials/hooks/body-end.html index 377470d9..0c27c8c3 100644 --- a/layouts/partials/hooks/body-end.html +++ b/layouts/partials/hooks/body-end.html @@ -15,3 +15,4 @@ */}} + diff --git a/layouts/partials/navbar.html b/layouts/partials/navbar.html index e78ee9c4..c96c30a9 100644 --- a/layouts/partials/navbar.html +++ b/layouts/partials/navbar.html @@ -8,9 +8,10 @@ {{ $cover := .HasShortcode "blocks/cover" }} -{{ define "partials/version-string" }} - {{ $ret := "unstable version"}} +{{ define "partials/version-selector" }} + {{ $version := .Site.Params.version }} + {{ $current := partial "current-version-short" . }} + + +{{ end }} - {{ $status := .Site.Params.version.status }} - {{ if ne $status "unstable"}} - {{ $path := path.Join "changelogs" }} +{{ define "partials/current-version-long" }} + {{ if eq .Site.Params.version.status "unstable" }} + unstable version + {{ else }} + version {{ partial "current-version-short" . }} + {{ end }} +{{ end }} - {{/* produces a string similar to "version v1.5" */}} - {{ $ret = delimit (slice "version v" .Site.Params.version.major "." .Site.Params.version.minor) "" }} - {{ end }} + +{{ define "partials/current-version-short" }} + {{ $ret := "unstable"}} + + {{ if ne .Site.Params.version.status "unstable"}} + {{/* produces a string similar to "version v1.5" */}} + {{ $ret = delimit (slice "v" .Site.Params.version.major "." .Site.Params.version.minor) "" }} + {{ end }} {{ return $ret }} {{ end }} diff --git a/static/js/version_selector.js b/static/js/version_selector.js new file mode 100644 index 00000000..c866c36d --- /dev/null +++ b/static/js/version_selector.js @@ -0,0 +1,32 @@ +window.addEventListener('DOMContentLoaded', () => { + const selector = document.getElementById("version-selector") + + // Get the current version number and check that it or "latest" appears in the URL. + let current = selector.querySelector("option[selected]").value + let current_segment + console.log("current", current) + if (window.location.href.includes("/" + current + "/")) { + current_segment = "/" + current + "/" + } else if (window.location.href.includes("/latest/")) { + current_segment = "/latest/" + } else { + // If not, ditch the selector dropdown. + let parent = selector.parentElement + let fallback = parent.querySelector("noscript") + parent.removeChild(fallback) + parent.removeChild(selector) + parent.appendChild(document.createTextNode(fallback.innerText)) + return + } + + selector.addEventListener("change", event => { + let chosen = event.target.value + if (chosen === "historical") { + // Go to the "historical version" in the current spec's revision. + let parts = window.location.href.split(current_segment, 2) + window.location.href = parts[0] + current_segment + "changelog/#historical-versions" + } else { + window.location.href = window.location.href.replace(current_segment, "/" + chosen + "/") + } + }) +}); From 201b1933dfc1d912acedabc995838414746bce8a Mon Sep 17 00:00:00 2001 From: David Robertson Date: Thu, 16 Jun 2022 11:21:34 +0100 Subject: [PATCH 2/2] Changelog --- changelogs/room_versions/newsfragments/1131.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/room_versions/newsfragments/1131.feature diff --git a/changelogs/room_versions/newsfragments/1131.feature b/changelogs/room_versions/newsfragments/1131.feature new file mode 100644 index 00000000..e4b1eba6 --- /dev/null +++ b/changelogs/room_versions/newsfragments/1131.feature @@ -0,0 +1 @@ +Dummy changelog to make CI happy. Add a very hacky version switcher to navigate between different spec versions.