diff --git a/CHANGELOG.md b/CHANGELOG.md index 227e2d3..de109a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This website is built from the `HEAD` of the `main` branch of the theme reposito Code changes to `main` that are *not* in the latest release: +- Fixed: incorrect navigation when `.html` omitted from URL by [@pdmosses] in [#1374] - Fixed: incorrect positioning of clickable area for navigation links on Safari by [@mattxwang] in [#1403] Docs changes made since the latest release: @@ -29,6 +30,7 @@ Docs changes made since the latest release: [@mitchnemirov]: https://github.com/mitchnemirov +[#1374]: https://github.com/just-the-docs/just-the-docs/pull/1374 [#1390]: https://github.com/just-the-docs/just-the-docs/pull/1390 [#1403]: https://github.com/just-the-docs/just-the-docs/pull/1403 diff --git a/assets/js/just-the-docs.js b/assets/js/just-the-docs.js index 4f0296d..bf3755f 100644 --- a/assets/js/just-the-docs.js +++ b/assets/js/just-the-docs.js @@ -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