Improve TOC handling
This commit is contained in:
@@ -38,14 +38,11 @@
|
||||
}
|
||||
|
||||
// get all titles in the page
|
||||
const titles = document.querySelectorAll('h2, h3')
|
||||
const titles = document.querySelectorAll('h1, h2, h3')
|
||||
const toc = document.getElementById('toc') as Element
|
||||
const toc_cnt = document.getElementById('toc-container') as Element
|
||||
|
||||
console.log(titles)
|
||||
|
||||
// if there's more than two titles (ie, there's more than just the article title and TOC title, then appropriate to show)
|
||||
if (titles.length > 2) {
|
||||
if (titles.length > 0) {
|
||||
toc_cnt.classList.add('lg:block')
|
||||
}
|
||||
|
||||
@@ -54,19 +51,7 @@
|
||||
|
||||
// Assign IDs in case they haven't been (by me)
|
||||
t.id = t.innerHTML
|
||||
|
||||
let depth = 1
|
||||
|
||||
// determine what depth to use
|
||||
switch (t.tagName) {
|
||||
case 'H2':
|
||||
depth = 1
|
||||
break
|
||||
case 'H3':
|
||||
depth = 2
|
||||
break
|
||||
}
|
||||
|
||||
let depth = t.tagName.substring(1) as number
|
||||
addLink(t, depth)
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user