-
Notifications
You must be signed in to change notification settings - Fork 3
Add version selector to Docs #1356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
283cd66
8a9a24a
3c135a9
805bb8b
ba5426d
e22f79c
2b47315
80391b7
707848d
a11b5ea
ddf9c11
319405f
50cd0be
435749a
1c24cc9
9575438
33466f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| # Generated documentation files | ||
| command_line_help.md | ||
| examples.md | ||
| versions.md |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # A script to generate theme/header.hbs from a Jinja2 template. | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from jinja2 import Environment, FileSystemLoader | ||
| from release import get_releases | ||
|
|
||
| DOCS_DIR = Path(__file__).parent.absolute() | ||
| REPO_ROOT = DOCS_DIR.parent | ||
|
|
||
|
|
||
| def generate_header_hbs() -> None: | ||
| """Write the theme/header.hbs file.""" | ||
| theme_dir = REPO_ROOT / "theme" | ||
| theme_dir.mkdir(parents=True, exist_ok=True) | ||
| path = theme_dir / "header.hbs" | ||
| print(f"Writing {path}") | ||
| env = Environment(loader=FileSystemLoader(DOCS_DIR / "templates")) | ||
| template = env.get_template("header.hbs.jinja") | ||
| releases = [ | ||
| {"label": release, "stable": i == 0} for i, release in enumerate(get_releases()) | ||
| ] | ||
| out = template.render(releases=releases) | ||
|
|
||
| with path.open("w", encoding="utf-8") as f: | ||
| f.write(out) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| generate_header_hbs() |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| From 2ee8d44b2c4a6b3b2e5ed1a546a3dd6ac2c20dab Mon Sep 17 00:00:00 2001 | ||
| From: Adrian D'Alessandro <a.dalessandro@imperial.ac.uk> | ||
| Date: Wed, 17 Jun 2026 18:59:07 +0100 | ||
| Subject: [PATCH] Remove other versions docs from contents | ||
|
|
||
| --- | ||
| docs/SUMMARY.md | 1 - | ||
| 1 file changed, 1 deletion(-) | ||
|
|
||
| diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md | ||
| index 38e09211..36f0c2ee 100644 | ||
| --- a/docs/SUMMARY.md | ||
| +++ b/docs/SUMMARY.md | ||
| @@ -25,4 +25,3 @@ | ||
| - [MUSE2 v2.0.0 (October 14, 2025)](release_notes/v2.0.0.md) | ||
| - [MUSE2 v2.1.0 (March 31, 2026)](release_notes/v2.1.0.md) | ||
| - [Next unreleased version](release_notes/upcoming.md) | ||
| -- [Other versions of documentation](versions.md) | ||
| -- | ||
| 2.50.1 (Apple Git-155) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| <style> | ||
| :root { --banner-height: 36px; } | ||
|
|
||
| #version-banner { | ||
| display: none; | ||
| position: fixed; | ||
| top: 0; left: 0; right: 0; | ||
| height: var(--banner-height); | ||
| z-index: 9999; | ||
| align-items: center; | ||
| justify-content: center; | ||
| font-size: 0.875em; | ||
| box-sizing: border-box; | ||
| padding: 0 16px; | ||
| } | ||
|
|
||
| #version-widget { | ||
| position: fixed; | ||
| bottom: 0; | ||
| right: 1rem; | ||
| z-index: 9999; | ||
| font-size: 0.85em; | ||
| font-family: sans-serif; | ||
| } | ||
|
|
||
| #version-widget:hover #version-list, | ||
| #version-widget:focus-within #version-list { | ||
| max-height: 300px; | ||
| } | ||
|
|
||
| #version-widget:hover #version-arrow, | ||
| #version-widget:focus-within #version-arrow { | ||
| transform: rotate(180deg); | ||
| } | ||
|
|
||
| #version-label { | ||
| display: block; | ||
| background: #0c3547; | ||
| color: #fff; | ||
| padding: 6px 12px; | ||
| border-radius: 4px 4px 0 0; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| #version-arrow { | ||
| display: inline-block; | ||
| transition: transform 0.2s ease; | ||
| } | ||
|
|
||
| #version-list { | ||
| list-style: none; | ||
| margin: 0; | ||
| padding: 0; | ||
| background: #fff; | ||
| color: #222; | ||
| border: 1px solid #ccc; | ||
| border-bottom: none; | ||
| max-height: 0; | ||
| overflow: hidden; | ||
| transition: max-height 0.2s ease; | ||
| } | ||
|
|
||
| #version-list li { | ||
| padding: 6px 12px; | ||
| white-space: nowrap; | ||
| border-bottom: 1px solid #eee; | ||
| } | ||
|
|
||
| #version-list a { | ||
| color: #0c3547; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| #version-list a:hover { | ||
| text-decoration: underline; | ||
| } | ||
| </style> | ||
|
|
||
| <div id="version-banner" role="status" aria-live="polite"></div> | ||
|
|
||
| <div id="version-widget"> | ||
| <ul id="version-list" aria-label="Documentation versions"></ul> | ||
| <span id="version-label" tabindex="0" role="button" aria-haspopup="listbox" aria-controls="version-list">docs: <span id="version-label-text"></span> <span id="version-arrow">▲</span></span> | ||
| </div> | ||
|
|
||
| <script> | ||
| (function () { | ||
| var path = window.location.pathname; | ||
| var banner = document.getElementById("version-banner"); | ||
| var labelText = document.getElementById("version-label-text"); | ||
| var list = document.getElementById("version-list"); | ||
|
|
||
| var versionMatch = /\/release\/(v[\d.]+)\//.exec(path); | ||
| var isDev = !versionMatch; | ||
| var currentVersion = isDev ? "development" : versionMatch[1]; | ||
| var isStable = false; | ||
|
|
||
| // Build version list | ||
| var pathToRoot = "{% raw %}{{path_to_root}}{% endraw %}"; | ||
| var versions = [ | ||
| { label: "development", stable: false }, | ||
| {%- for release in releases %} | ||
| { label: "{{ release.label }}", stable: {{ release.stable|lower }} }, | ||
| {%- endfor %} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of having a separate For example, maybe you could change the objects in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I have done similar to this. I have made the objects include an additional This has resulted in not needing to build the separate So, currently we'll only see a banner for version 2.0.0 and the development version. |
||
| ]; | ||
|
|
||
| function hrefFor(label) { | ||
| if (isDev) { | ||
| if (label === "development") return pathToRoot; | ||
| return pathToRoot + "release/" + label + "/index.html"; | ||
| } | ||
| // Old versioned docs (e.g. /release/v2.0.0/) | ||
| if (label === "development") return pathToRoot + "../../index.html"; | ||
| return pathToRoot + "../" + label + "/index.html"; | ||
| } | ||
|
|
||
| versions.forEach(function (v) { | ||
| var li = document.createElement("li"); | ||
|
|
||
| versionLabel = v.stable ? v.label + " (stable)" : v.label; | ||
|
|
||
| if (v.label === currentVersion) { | ||
| // Determine if current version is the stable release | ||
| isStable = v.stable; | ||
| // Set widget label | ||
| labelText.textContent = versionLabel; | ||
|
|
||
| var strong = document.createElement("strong"); | ||
| strong.textContent = versionLabel; | ||
| li.appendChild(strong); | ||
| } else { | ||
| var a = document.createElement("a"); | ||
| a.href = hrefFor(v.label); | ||
| a.textContent = versionLabel; | ||
| li.appendChild(a); | ||
| } | ||
| list.appendChild(li); | ||
| }); | ||
|
|
||
| // Banner (not shown for stable) | ||
| if (isStable) return; | ||
|
|
||
| if (isDev) { | ||
| banner.innerHTML = | ||
| "This is the <strong>\u00a0development version\u00a0</strong> of the MUSE2 documentation. " + | ||
| "For older releases, use the version selector in the bottom right corner of this page."; | ||
| banner.style.backgroundColor = "#fff3cd"; | ||
| banner.style.borderBottom = "1px solid #ffc107"; | ||
| banner.style.color = "#664d03"; | ||
| } else { | ||
| var version = versionMatch[1]; | ||
| banner.innerHTML = | ||
| "You are viewing docs for <strong>\u00a0" + version + "\u00a0</strong> of MUSE2. " + | ||
| "For newer releases, use the version selector in the bottom right corner of this page."; | ||
| banner.style.backgroundColor = "#f8d7da"; | ||
| banner.style.borderBottom = "1px solid #f5c2c7"; | ||
| banner.style.color = "#842029"; | ||
| } | ||
|
|
||
| banner.style.display = "flex"; | ||
|
|
||
| var s = document.createElement("style"); | ||
| s.textContent = | ||
| "body { padding-top: var(--banner-height); }" + | ||
| "#mdbook-menu-bar.sticky { top: var(--banner-height) !important; }" + | ||
| "#mdbook-sidebar { top: var(--banner-height) !important; height: calc(100vh - var(--banner-height)) !important; }"; | ||
| document.head.appendChild(s); | ||
| })(); | ||
| </script> | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.