Skip to content
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

[Doc] Fix navigation panel version in 404.html #8311

Merged
merged 1 commit into from
Oct 26, 2022
Merged
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
24 changes: 24 additions & 0 deletions docs/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@
<p><a href="#" onClick="history.go(-1); return false;">Go back</a></p>

<script>
// helper function to replace the Navigation content
function replaceNavigationContent(text) {
var tmpElement = document.createElement('div');
tmpElement.innerHTML = text;
var content = document.querySelector('.sidenav');
content.innerHTML = tmpElement.querySelector('.sidenav').innerHTML;
buildPageToC();
}

// helper function to fetch the Navigation content for the current version and
// replace it in the DOM
function replaceNavigationWithVersion(version) {
var location = document.location.href.split('#')[0];
var locationSlices = location.split('/');
var href = [...locationSlices.slice(0, locationSlices.length - 2), version, 'Readme.html'].join('/');
// fetch the new content
fetch(href)
.then(res => res.text())
.then(replaceNavigationContent);
}

let docPageRoot;
const docPageRegexp = /(.*\/doc\/\d+\.\d+\/).*/;
const versionRegexp = /.*\/doc\/(\d+\.\d+)\/.*/;
Expand All @@ -62,5 +83,8 @@
'doc-version-number'
)[1].innerText = version;
document.getElementById('doc-version').style.display = 'block';

// Replace the Navigation content with the one for the current version
replaceNavigationWithVersion(version);
}
</script>