mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 05:13:33 -06:00
Fix navigation when .html
omitted (#1374)
* Prefer exact match of pathname * Update CHANGELOG.md
This commit is contained in:
@@ -487,11 +487,28 @@ jtd.setTheme = function(theme) {
|
||||
// and not have the slash on GitHub Pages
|
||||
|
||||
function navLink() {
|
||||
var href = document.location.pathname;
|
||||
if (href.endsWith('/') && href != '/') {
|
||||
href = href.slice(0, -1);
|
||||
var pathname = document.location.pathname;
|
||||
|
||||
var navLink = document.getElementById('site-nav').querySelector('a[href="' + pathname + '"]');
|
||||
if (navLink) {
|
||||
return navLink;
|
||||
}
|
||||
return document.getElementById('site-nav').querySelector('a[href="' + href + '"], a[href="' + href + '/"]');
|
||||
|
||||
// The `permalink` setting may produce navigation links whose `href` ends with `/` or `.html`.
|
||||
// To find these links when `/` is omitted from or added to pathname, or `.html` is omitted:
|
||||
|
||||
if (pathname.endsWith('/') && pathname != '/') {
|
||||
pathname = pathname.slice(0, -1);
|
||||
}
|
||||
|
||||
if (pathname != '/') {
|
||||
navLink = document.getElementById('site-nav').querySelector('a[href="' + pathname + '"], a[href="' + pathname + '/"], a[href="' + pathname + '.html"]');
|
||||
if (navLink) {
|
||||
return navLink;
|
||||
}
|
||||
}
|
||||
|
||||
return null; // avoids `undefined`
|
||||
}
|
||||
|
||||
// Scroll site-nav to ensure the link to the current page is visible
|
||||
|
Reference in New Issue
Block a user