Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/scripts/generate-redirect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ cat > "$OUTPUT" << HTMLEOF
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=/${LATEST}/">
<meta http-equiv="refresh" content="0; url=./${LATEST}/">
<title>Redirecting to latest docs</title>
</head>
<body>
<p>Redirecting to <a href="/${LATEST}/">latest documentation (${LATEST})</a></p>
<p>Redirecting to <a href="./${LATEST}/">latest documentation (${LATEST})</a></p>
</body>
</html>
HTMLEOF
Expand Down
16 changes: 11 additions & 5 deletions docs/src/version-selector.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
(function () {
'use strict';

var pathSegments = window.location.pathname.split('/');
var currentVersion = pathSegments[1] || '';
var currentPage = pathSegments.slice(2).join('/');
// The script is served from <site-root>/<version>/src/version-selector.js.
// Use its URL to derive the site root and current version, so paths work
// regardless of whether docs are hosted at the domain root or a subpath.
var scriptUrl = document.currentScript.src;
var versionBase = new URL('..', scriptUrl).href;
var siteRoot = new URL('..', versionBase).href;
var currentVersion = versionBase.replace(/\/$/, '').split('/').pop() || '';
var pageUrl = window.location.href;
var currentPage = pageUrl.startsWith(versionBase) ? pageUrl.substring(versionBase.length) : '';

fetch('/versions.json')
fetch(new URL('versions.json', siteRoot).href)
.then(function (res) {
if (!res.ok) throw new Error(res.status);
return res.json();
Expand Down Expand Up @@ -34,7 +40,7 @@
if (select.options.length === 0) return;

select.addEventListener('change', function () {
window.location.href = '/' + this.value + '/' + currentPage;
window.location.href = new URL(this.value + '/' + currentPage, siteRoot).href;
});

var container = document.querySelector('.right-buttons');
Expand Down
Loading