-
Notifications
You must be signed in to change notification settings - Fork 9
Publish ref docs to GitHub Pages with versioning and version picker #341
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
622804c
Publish ref docs to GitHub Pages with versioning and version picker
kirre-bylund daab79a
chore: deploy only on release or dispatch; dispatch deploys to branch…
kirre-bylund f73a701
fix: address Copilot review - fix version-picker for search/ subdirs,…
kirre-bylund File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /** | ||
| * version-picker.js — LootLocker Unreal SDK | ||
| * | ||
| * Replaces the static #ll-topnav-version span with a <select> dropdown | ||
| * that lets users navigate between published doc versions. | ||
| * | ||
| * The list of available versions is fetched from versions.json at the root | ||
| * of the published site (one level above the current version directory). | ||
| * Falls back gracefully to the static badge when versions.json is unavailable | ||
| * (e.g. local Doxygen builds). | ||
| * | ||
| * Expected versions.json shape: | ||
| * [ | ||
| * { "version": "latest", "path": "latest/" }, | ||
| * { "version": "v2.5.0", "path": "v2.5.0/" } | ||
| * ] | ||
| * | ||
| * URL resolution: | ||
| * The script detects the current version directory by looking at the last | ||
| * path segment of the page URL and resolves versions.json relative to the | ||
| * site root (two levels up from the current page, one for the HTML file | ||
| * and one for the version directory). | ||
| */ | ||
| (function () { | ||
| 'use strict'; | ||
|
|
||
| /** Normalize pathname: treat a trailing slash as /index.html so that | ||
| * directory-style URLs (e.g. /latest/) are handled correctly. */ | ||
| function normalizePath(pathname) { | ||
| return pathname.endsWith('/') ? pathname + 'index.html' : pathname; | ||
| } | ||
|
|
||
| /** Fetch versions.json by trying candidate site roots 2 then 3 path segments | ||
| * above the current page. This covers both the common Doxygen layout | ||
| * (/<repo>/<version>/page.html) and the search subdirectory | ||
| * (/<repo>/<version>/search/page.html). | ||
| * Resolves with { root, versions } on success. */ | ||
| function fetchVersions() { | ||
| var loc = window.location; | ||
| var parts = normalizePath(loc.pathname).split('/'); | ||
| var tried = Promise.reject(new Error('no candidates')); | ||
| for (var strip = 2; strip <= 3; strip++) { | ||
| (function (s) { | ||
| if (parts.length > s) { | ||
| var rootPath = parts.slice(0, parts.length - s).join('/') + '/'; | ||
| var root = loc.protocol + '//' + loc.host + rootPath; | ||
| tried = tried.catch(function () { | ||
| return fetch(root + 'versions.json', { cache: 'no-cache' }) | ||
| .then(function (r) { | ||
| if (!r.ok) throw new Error('versions.json not found at ' + root); | ||
| return r.json().then(function (v) { return { root: root, versions: v }; }); | ||
| }); | ||
| }); | ||
| } | ||
| })(strip); | ||
| } | ||
| return tried; | ||
| } | ||
|
|
||
| function buildPicker(result) { | ||
| var badge = document.getElementById('ll-topnav-version'); | ||
| if (!badge) return; | ||
|
|
||
| var loc = window.location; | ||
| var root = result.root; | ||
| var versions = result.versions; | ||
|
|
||
| // Derive the version dir and page path relative to it from the current URL | ||
| var rootPath = new URL(root).pathname; // e.g. '/unreal-sdk/' | ||
| var relative = normalizePath(loc.pathname).slice(rootPath.length); // e.g. 'latest/foo.html' | ||
| var slash = relative.indexOf('/'); | ||
| var currentVersionPath = slash !== -1 ? relative.slice(0, slash + 1) : 'latest/'; | ||
| var page = slash !== -1 ? relative.slice(slash + 1) : 'index.html'; | ||
| var suffix = loc.search + loc.hash; // preserve query string and anchor | ||
|
|
||
| var select = document.createElement('select'); | ||
| select.id = 'll-version-picker'; | ||
| select.setAttribute('aria-label', 'Select documentation version'); | ||
| select.title = 'Switch version'; | ||
|
|
||
| versions.forEach(function (entry) { | ||
| var opt = document.createElement('option'); | ||
| opt.value = root + entry.path + page + suffix; | ||
| opt.textContent = entry.version; | ||
| if (entry.path === currentVersionPath) { | ||
| opt.selected = true; | ||
| } | ||
| select.appendChild(opt); | ||
| }); | ||
|
|
||
| select.addEventListener('change', function () { | ||
| window.location.href = select.value; | ||
| }); | ||
|
|
||
| badge.parentNode.replaceChild(select, badge); | ||
| } | ||
|
|
||
| function init() { | ||
| fetchVersions() | ||
| .then(function (result) { | ||
| if (Array.isArray(result.versions) && result.versions.length > 0) { | ||
| buildPicker(result); | ||
| } | ||
| }) | ||
| .catch(function () { | ||
| // Graceful fallback — keep the static badge as-is | ||
| }); | ||
| } | ||
|
|
||
| if (document.readyState === 'loading') { | ||
| document.addEventListener('DOMContentLoaded', init); | ||
| } else { | ||
| init(); | ||
| } | ||
| }()); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.