File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -13,17 +13,34 @@ class MDBookSidebarScrollbox extends HTMLElement {
1313 let current_page = document.location.href.toString().split("#")[0];
1414 if (current_page.endsWith("/")) {
1515 current_page += "index.html";
16+ } else if (!current_page.endsWith(".html")) {
17+ current_page += ".html";
1618 }
1719 var links = Array.prototype.slice.call(this.querySelectorAll("a"));
1820 var l = links.length;
21+
22+ function isCurrentPage(i) {
23+ let href = links[i].href;
24+ // special case for root
25+ if (i === 0 && path_to_root === "" && current_page.endsWith("/index.html")) {
26+ return true;
27+ }
28+ if (href.endsWith("/")) {
29+ href += "index.html";
30+ } else if (!href.endsWith(".html")) {
31+ href += ".html";
32+ }
33+ return current_page === href;
34+ }
35+
1936 for (var i = 0; i < l; ++i) {
2037 var link = links[i];
2138 var href = link.getAttribute("href");
2239 if (href && !href.startsWith("#") && !/^(?:[a-z+]+:)?\/\//.test(href)) {
2340 link.href = path_to_root + href;
2441 }
2542 // The "index" page is supposed to alias the first chapter in the book.
26- if (link.href === current_page || (i === 0 && path_to_root === "" && current_page.endsWith("/index.html") )) {
43+ if (isCurrentPage(i )) {
2744 link.classList.add("active");
2845 var parent = link.parentElement;
2946 if (parent && parent.classList.contains("chapter-item")) {
You can’t perform that action at this time.
0 commit comments