toc.js: marking active page in toc when redirected to url without .html
suffix
#2570
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
When serving the book through services that redirects
/foo/bar.html
->/foo/bar
, the page in TOC isn't marked as active because the toc uses an exact match with thehref
on thea
tag.This is a common behavior for services such as GH pages, and tools like
npx serve
(which actually redirects to paths without.html
and serves the html anyway. in this case the active page never gets marked)Fix
Refactored the check for if a link is current page, and loosened the condition so the
.html
suffix is optional:/foo
and/foo.html
will match/foo.html
link/foo/
,/foo/index
,/foo/index.html
will match/foo/index.html
linkIf the active page is still not found, it will try to map
/foo
to/foo/index.html
, which is the redirect behavior of some services/toolsTesting
Verified each link in the TOC now gets highlighted when switching to the page