mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-04-18 17:12:23 -06:00
Fix navigation when .html
omitted (#1374)
* Prefer exact match of pathname * Update CHANGELOG.md
This commit is contained in:
parent
e96bf6ae3d
commit
742281635f
@ -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:
|
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]
|
- Fixed: incorrect positioning of clickable area for navigation links on Safari by [@mattxwang] in [#1403]
|
||||||
|
|
||||||
Docs changes made since the latest release:
|
Docs changes made since the latest release:
|
||||||
@ -29,6 +30,7 @@ Docs changes made since the latest release:
|
|||||||
|
|
||||||
[@mitchnemirov]: https://github.com/mitchnemirov
|
[@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
|
[#1390]: https://github.com/just-the-docs/just-the-docs/pull/1390
|
||||||
[#1403]: https://github.com/just-the-docs/just-the-docs/pull/1403
|
[#1403]: https://github.com/just-the-docs/just-the-docs/pull/1403
|
||||||
|
|
||||||
|
@ -487,11 +487,28 @@ jtd.setTheme = function(theme) {
|
|||||||
// and not have the slash on GitHub Pages
|
// and not have the slash on GitHub Pages
|
||||||
|
|
||||||
function navLink() {
|
function navLink() {
|
||||||
var href = document.location.pathname;
|
var pathname = document.location.pathname;
|
||||||
if (href.endsWith('/') && href != '/') {
|
|
||||||
href = href.slice(0, -1);
|
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
|
// Scroll site-nav to ensure the link to the current page is visible
|
||||||
|
Loading…
x
Reference in New Issue
Block a user