mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 11:41:17 +02:00
perf: optimize dom selectors for better performance
This commit is contained in:
parent
bfe3771571
commit
beb3386edc
10 changed files with 26 additions and 23 deletions
|
@ -154,7 +154,7 @@ function setupTOCHighlight() {
|
|||
if (!tocContent)
|
||||
return
|
||||
|
||||
const tocLinks = tocContent.querySelectorAll('a')
|
||||
const tocLinks = tocContent.getElementsByTagName('a')
|
||||
if (tocLinks.length === 0)
|
||||
return
|
||||
|
||||
|
@ -163,7 +163,7 @@ function setupTOCHighlight() {
|
|||
|
||||
// Build mapping from heading IDs to TOC links
|
||||
const headingMap = new Map<string, HTMLAnchorElement>()
|
||||
tocLinks.forEach((link) => {
|
||||
Array.from(tocLinks).forEach((link) => {
|
||||
const id = link.getAttribute('href')?.substring(1)
|
||||
if (id)
|
||||
headingMap.set(id, link as HTMLAnchorElement)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue