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'
15import MdReg from 'markdown-it-regexp' 15import MdReg from 'markdown-it-regexp'
16import type { MarkdownRenderer } from 'vitepress' 16import type { MarkdownRenderer } from 'vitepress'
17import { 17import {
18 getCollapsibleHeadingAnchor,
18 getTabAnchor, 19 getTabAnchor,
19 getTabHeadingAnchor, 20 getTabHeadingAnchor,
20 getUniqueAnchor, 21 getUniqueAnchor,
@@ -259,7 +260,9 @@ function injectSearchHeadings(src: string) {
259 '', 260 '',
260 `${indent}${ 261 `${indent}${
261 '#'.repeat(headingLevel) 262 '#'.repeat(headingLevel)
262 } ${headingTitle} {.collapsible-search-heading}`, 263 } ${headingTitle} {#${
264 getCollapsibleHeadingAnchor(collapsibleAnchor)
265 } .collapsible-search-heading}`,
263 '' 266 ''
264 ) 267 )
265 i += 3 268 i += 3
docs/.vitepress/plugins/urlSearchPlugin.ts +9 −1
@@ -2,8 +2,10 @@ import { writeFileSync } from 'node:fs'
2import { join } from 'node:path' 2import { join } from 'node:path'
3import { renderEmojiShortcodes } from '../configs/markdown/emoji' 3import { renderEmojiShortcodes } from '../configs/markdown/emoji'
4import { 4import {
5 getCollapsibleHeadingAnchor,
5 getTabAnchor, 6 getTabAnchor,
6 getTabHeadingAnchor, 7 getTabHeadingAnchor,
8 getUniqueAnchor,
7 parseTabLabel, 9 parseTabLabel,
8 slugifyAnchor, 10 slugifyAnchor,
9 stripHeadingMarkup 11 stripHeadingMarkup
@@ -39,6 +41,7 @@ function extractSearchMetadataFromMarkdown(
39 const headingStack: string[] = [] 41 const headingStack: string[] = []
40 const slugCounts = new Map<string, number>() 42 const slugCounts = new Map<string, number>()
41 const tabAnchorCounts = new Map<string, number>() 43 const tabAnchorCounts = new Map<string, number>()
44 const collapsibleAnchorCounts = new Map<string, number>()
42 const containerStack: string[] = [] 45 const containerStack: string[] = []
43 const tabPath: string[] = [] 46 const tabPath: string[] = []
44 const tabResetStack: { 47 const tabResetStack: {
@@ -164,6 +167,10 @@ function extractSearchMetadataFromMarkdown(
164 headings: [...headingStack] 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 let nextLine = i + 1 174 let nextLine = i + 1
168 while (nextLine < lines.length && lines[nextLine].trim() === '') { 175 while (nextLine < lines.length && lines[nextLine].trim() === '') {
169 nextLine++ 176 nextLine++
@@ -175,7 +182,8 @@ function extractSearchMetadataFromMarkdown(
175 if (!/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) { 182 if (!/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) {
176 setHeading( 183 setHeading(
177 containerStack.includes('tabs') ? 3 : 2, 184 containerStack.includes('tabs') ? 3 : 2,
178 collapsibleMatch[2].trim() 185 parsed.label,
186 getCollapsibleHeadingAnchor(collapsibleAnchor)
179 ) 187 )
180 } 188 }
181 continue 189 continue
docs/.vitepress/theme/Layout.vue +1 −3
@@ -539,9 +539,7 @@ const tryOpenAnchoredContent = async () => {
539 return 539 return
540 } 540 }
541 541
542 if ( 542 if (target.classList.contains('tab-search-heading')) {
543 !requestedTabs.length && target.classList.contains('tab-search-heading')
544 ) {
545 const tabs = target.closest<HTMLElement>('.plugin-tabs') 543 const tabs = target.closest<HTMLElement>('.plugin-tabs')
546 if (tabs) { 544 if (tabs) {
547 window.history.replaceState( 545 window.history.replaceState(
docs/.vitepress/theme/components/Search.vue +18 −4
@@ -1580,10 +1580,24 @@ onKeyStroke('Tab', (event) => {
1580const router = useRouter() 1580const router = useRouter()
1581 1581
1582function buildResultHref(pageId: string, tabs?: string[], anchor = '') { 1582function buildResultHref(pageId: string, tabs?: string[], anchor = '') {
1583 const query = tabs?.length 1583 const params: string[] = []
1584 ? `?tabs=${tabs.map((tab) => encodeURIComponent(tab)).join(',')}` 1584 if (tabs?.length) {
1585 : '' 1585 params.push(`tabs=${tabs.map((tab) => encodeURIComponent(tab)).join(',')}`)
1586 const hash = anchor ? `#${encodeURIComponent(anchor)}` : '' 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 return `${pageId}${query}${hash}` 1601 return `${pageId}${query}${hash}`
1588} 1602}
1589 1603
docs/.vitepress/utils/tabAnchors.ts +4
@@ -59,3 +59,7 @@ export function getTabAnchor(
59export function getTabHeadingAnchor(tabAnchor: string) { 59export function getTabHeadingAnchor(tabAnchor: string) {
60 return `tab-${tabAnchor}` 60 return `tab-${tabAnchor}`
61} 61}
62
63export function getCollapsibleHeadingAnchor(collapsibleAnchor: string) {
64 return `collapsible-${collapsibleAnchor}`
65}