Skip to content

Commit 58cda3b

Browse files
authored
Match RTD directory URLs to TOC index.html (#153)
1 parent 1c14c63 commit 58cda3b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

docs/_static/toc-highlight.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,24 @@ document.addEventListener('DOMContentLoaded', function() {
1010
const parentUrlObj = new URL(parentUrl);
1111

1212
// Compare the pathname (ignoring hash and query parameters)
13-
if (linkUrl.pathname === parentUrlObj.pathname) {
13+
const linkPath = linkUrl.pathname;
14+
const parentPath = parentUrlObj.pathname;
15+
16+
// Check for direct match first
17+
let isMatch = linkPath === parentPath;
18+
19+
if (!isMatch) {
20+
// If no direct match and parent path doesn't end with a file, try appending index.html
21+
const lastSegment = parentPath.split('/').pop();
22+
const endsWithFile = lastSegment && lastSegment.includes('.');
23+
24+
if (!endsWithFile) {
25+
isMatch = linkPath === parentPath + 'index.html' ||
26+
linkPath === parentPath.replace(/\/$/, '') + '/index.html';
27+
}
28+
}
29+
30+
if (isMatch) {
1431
link.parentElement.classList.add('current-page');
1532
currentPageElement = link.parentElement;
1633
}

0 commit comments

Comments
 (0)