File tree 1 file changed +18
-1
lines changed
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 {
13
13
let current_page = document.location.href.toString().split("#")[0];
14
14
if (current_page.endsWith("/")) {
15
15
current_page += "index.html";
16
+ } else if (!current_page.endsWith(".html")) {
17
+ current_page += ".html";
16
18
}
17
19
var links = Array.prototype.slice.call(this.querySelectorAll("a"));
18
20
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
+
19
36
for (var i = 0; i < l; ++i) {
20
37
var link = links[i];
21
38
var href = link.getAttribute("href");
22
39
if (href && !href.startsWith("#") && !/^(?:[a-z+]+:)?\/\//.test(href)) {
23
40
link.href = path_to_root + href;
24
41
}
25
42
// 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 )) {
27
44
link.classList.add("active");
28
45
var parent = link.parentElement;
29
46
if (parent && parent.classList.contains("chapter-item")) {
You can’t perform that action at this time.
0 commit comments