Skip to content

Commit 85bc477

Browse files
committed
fix(docs): update ToC links
1 parent e8b3fbd commit 85bc477

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

super.so-theme-docs/script.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ function onPageLoad() {
3030

3131
document.addEventListener("DOMContentLoaded", onPageLoad);
3232

33+
function textToAnchorLink(text) {
34+
return text.replace(/[\W_]+/g,"-");
35+
}
36+
3337
function addHeaderLink () {
3438
[...document.querySelectorAll("h1.notion-heading")].map(item => {
3539
let span = document.createElement('span');
36-
let anchor_id = item.textContent.replace(/[\W_]+/g,"-");
40+
let anchor_id = textToAnchorLink(item.textContent);
3741
span.id = anchor_id;
3842
span.className = "notion-heading__anchor"
3943
let ahref = document.createElement('a');
@@ -46,3 +50,12 @@ function addHeaderLink () {
4650
}
4751

4852
document.addEventListener("DOMContentLoaded", addHeaderLink);
53+
54+
function fixToCLinks () {
55+
[...document.querySelectorAll("li.notion-table-of-contents__item > a")].map(item => {
56+
let anchor_id = textToAnchorLink(item.querySelector("span span span").textContent)
57+
item.href = "#" + anchor_id;
58+
});
59+
}
60+
61+
document.addEventListener("DOMContentLoaded", fixToCLinks);

0 commit comments

Comments
 (0)