Commit 7d4b1df360
Unsigned
Layout: unified · split
docs/.vitepress/theme/Layout.vue +15 −4
| @@ -157,6 +157,13 @@ const openCollapsibles = async (target: HTMLElement) => { | ||
| 157 | 157 | if (tagName.length === 2 && tagName[0] === 'H') { |
| 158 | 158 | const level = +tagName[1] |
| 159 | 159 | if (level >= 1 && level <= 6) { |
| 160 | const terms = getSearchTerms(searchQuery) | |
| 161 | const detailsContainsTerms = (d: HTMLElement) => { | |
| 162 | if (!terms.length) return false | |
| 163 | const text = (d.textContent ?? '').toLowerCase() | |
| 164 | return terms.every((term) => text.includes(term)) | |
| 165 | } | |
| 166 | ||
| 160 | 167 | let sibling = target.nextElementSibling |
| 161 | 168 | |
| 162 | 169 | while (sibling) { |
| @@ -167,14 +174,18 @@ const openCollapsibles = async (target: HTMLElement) => { | ||
| 167 | 174 | ) break |
| 168 | 175 | |
| 169 | 176 | if (siblingTag === 'DETAILS') { |
| 170 | ;(sibling as HTMLDetailsElement).open = true | |
| 171 | if (scrollTarget === target) scrollTarget = sibling as HTMLElement | |
| 177 | if (detailsContainsTerms(sibling as HTMLElement)) { | |
| 178 | ;(sibling as HTMLDetailsElement).open = true | |
| 179 | if (scrollTarget === target) scrollTarget = sibling as HTMLElement | |
| 180 | } | |
| 172 | 181 | } |
| 173 | 182 | |
| 174 | 183 | const nested = sibling.getElementsByTagName('details') |
| 175 | 184 | for (let i = 0, len = nested.length; i < len; i++) { |
| 176 | nested[i].open = true | |
| 177 | if (scrollTarget === target) scrollTarget = nested[i] | |
| 185 | if (detailsContainsTerms(nested[i])) { | |
| 186 | nested[i].open = true | |
| 187 | if (scrollTarget === target) scrollTarget = nested[i] | |
| 188 | } | |
| 178 | 189 | } |
| 179 | 190 | |
| 180 | 191 | sibling = sibling.nextElementSibling |