-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Problem
If the built docs are being hosted on a site that automatically strips the .html from urls (e.g. example.com/page.html -> example.com/page) then the section headers aren't displayed for the current page and the current page isn't even highlighted.
Steps
- Build mdBook docs
- Host docs on website/service that removes
.htmlfrom URLs - Navigate to a page with section headers
A good way to reproduce locally is mdbook serve (which has .html) vs. npx serve (which strips .html)
(My npx serve version is 14.2.0)
Possible Solution(s)
I fixed this problem with the following code in toc.js, albeit a bit hacky:
// Set the current, active page, and reveal it if it's hidden
let current_page = document.location.href.toString().split('#')[0].split('?')[0];
+ if (!current_page.endsWith(".html")) {
+ current_page += ".html";
+ }
if (current_page.endsWith('/')) {
current_page += 'index.html';
}This will essentially pretend the URL still has the .html, even if it doesn't actually. I saw no problems when testing this code, it does get wiped out whenever the docs are rebuilt though (understandably.)
Notes
Another possible solution would be to add a flag that allows customization of the generated links. For example:
[output.html]
hrefs-include-extension=false # (where default would be true)Version
mdbook v0.5.1

