Commit eba2b2a9e0
eba2b2a9e05bf7f920fe725fb457baec730cc763
parent: 92ee7baf0e
Unsigned
Duck <57977673+woducku@users.noreply.github.com> · 2026-06-30 05:46 UTC
fixes
Layout: unified · split
docs/.vitepress/configs/markdown/index.ts
+4 −1
| @@ -15,6 +15,7 @@ import { imgSize } from '@mdit/plugin-img-size' |
| 15 | 15 | import MdReg from 'markdown-it-regexp' |
| 16 | 16 | import type { MarkdownRenderer } from 'vitepress' |
| 17 | 17 | import { |
| 18 | getCollapsibleHeadingAnchor, |
| 18 | 19 | getTabAnchor, |
| 19 | 20 | getTabHeadingAnchor, |
| 20 | 21 | getUniqueAnchor, |
| @@ -259,7 +260,9 @@ function injectSearchHeadings(src: string) { |
| 259 | 260 | '', |
| 260 | 261 | `${indent}${ |
| 261 | 262 | '#'.repeat(headingLevel) |
| 262 | | } ${headingTitle} {.collapsible-search-heading}`, |
| 263 | } ${headingTitle} {#${ |
| 264 | getCollapsibleHeadingAnchor(collapsibleAnchor) |
| 265 | } .collapsible-search-heading}`, |
| 263 | 266 | '' |
| 264 | 267 | ) |
| 265 | 268 | i += 3 |
docs/.vitepress/plugins/urlSearchPlugin.ts
+9 −1
| @@ -2,8 +2,10 @@ import { writeFileSync } from 'node:fs' |
| 2 | 2 | import { join } from 'node:path' |
| 3 | 3 | import { renderEmojiShortcodes } from '../configs/markdown/emoji' |
| 4 | 4 | import { |
| 5 | getCollapsibleHeadingAnchor, |
| 5 | 6 | getTabAnchor, |
| 6 | 7 | getTabHeadingAnchor, |
| 8 | getUniqueAnchor, |
| 7 | 9 | parseTabLabel, |
| 8 | 10 | slugifyAnchor, |
| 9 | 11 | stripHeadingMarkup |
| @@ -39,6 +41,7 @@ function extractSearchMetadataFromMarkdown( |
| 39 | 41 | const headingStack: string[] = [] |
| 40 | 42 | const slugCounts = new Map<string, number>() |
| 41 | 43 | const tabAnchorCounts = new Map<string, number>() |
| 44 | const collapsibleAnchorCounts = new Map<string, number>() |
| 42 | 45 | const containerStack: string[] = [] |
| 43 | 46 | const tabPath: string[] = [] |
| 44 | 47 | const tabResetStack: { |
| @@ -164,6 +167,10 @@ function extractSearchMetadataFromMarkdown( |
| 164 | 167 | headings: [...headingStack] |
| 165 | 168 | }) |
| 166 | 169 | |
| 170 | const parsed = parseTabLabel(collapsibleMatch[2]) |
| 171 | const collapsibleAnchor = parsed.anchor || |
| 172 | getUniqueAnchor(parsed.label, collapsibleAnchorCounts) |
| 173 | |
| 167 | 174 | let nextLine = i + 1 |
| 168 | 175 | while (nextLine < lines.length && lines[nextLine].trim() === '') { |
| 169 | 176 | nextLine++ |
| @@ -175,7 +182,8 @@ function extractSearchMetadataFromMarkdown( |
| 175 | 182 | if (!/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) { |
| 176 | 183 | setHeading( |
| 177 | 184 | containerStack.includes('tabs') ? 3 : 2, |
| 178 | | collapsibleMatch[2].trim() |
| 185 | parsed.label, |
| 186 | getCollapsibleHeadingAnchor(collapsibleAnchor) |
| 179 | 187 | ) |
| 180 | 188 | } |
| 181 | 189 | continue |
docs/.vitepress/theme/Layout.vue
+1 −3
| @@ -539,9 +539,7 @@ const tryOpenAnchoredContent = async () => { |
| 539 | 539 | return |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | | if ( |
| 543 | | !requestedTabs.length && target.classList.contains('tab-search-heading') |
| 544 | | ) { |
| 542 | if (target.classList.contains('tab-search-heading')) { |
| 545 | 543 | const tabs = target.closest<HTMLElement>('.plugin-tabs') |
| 546 | 544 | if (tabs) { |
| 547 | 545 | window.history.replaceState( |
docs/.vitepress/theme/components/Search.vue
+18 −4
| @@ -1580,10 +1580,24 @@ onKeyStroke('Tab', (event) => { |
| 1580 | 1580 | const router = useRouter() |
| 1581 | 1581 | |
| 1582 | 1582 | function buildResultHref(pageId: string, tabs?: string[], anchor = '') { |
| 1583 | | const query = tabs?.length |
| 1584 | | ? `?tabs=${tabs.map((tab) => encodeURIComponent(tab)).join(',')}` |
| 1585 | | : '' |
| 1586 | | const hash = anchor ? `#${encodeURIComponent(anchor)}` : '' |
| 1583 | const params: string[] = [] |
| 1584 | if (tabs?.length) { |
| 1585 | params.push(`tabs=${tabs.map((tab) => encodeURIComponent(tab)).join(',')}`) |
| 1586 | } |
| 1587 | |
| 1588 | let hash = '' |
| 1589 | if (anchor.startsWith('collapsible-')) { |
| 1590 | const collapsible = anchor.slice('collapsible-'.length) |
| 1591 | if (collapsible) params.push(`c=${encodeURIComponent(collapsible)}`) |
| 1592 | } else { |
| 1593 | const lastTab = tabs?.length ? tabs[tabs.length - 1] : '' |
| 1594 | const isRedundantTabHeading = Boolean(anchor) && anchor === `tab-${lastTab}` |
| 1595 | if (anchor && !isRedundantTabHeading) { |
| 1596 | hash = `#${encodeURIComponent(anchor)}` |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | const query = params.length ? `?${params.join('&')}` : '' |
| 1587 | 1601 | return `${pageId}${query}${hash}` |
| 1588 | 1602 | } |
| 1589 | 1603 | |
docs/.vitepress/utils/tabAnchors.ts
+4
| @@ -59,3 +59,7 @@ export function getTabAnchor( |
| 59 | 59 | export function getTabHeadingAnchor(tabAnchor: string) { |
| 60 | 60 | return `tab-${tabAnchor}` |
| 61 | 61 | } |
| 62 | |
| 63 | export function getCollapsibleHeadingAnchor(collapsibleAnchor: string) { |
| 64 | return `collapsible-${collapsibleAnchor}` |
| 65 | } |