Commit bca6c48151

bca6c4815147afb90105bf46a34fbbd66f7113e6

parent: e1e52c333f

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-06-03 04:53 UTC

update

Layout: unified · split

docs/.vitepress/configs/index.ts +4 −3
@@ -30,9 +30,6 @@ const GIT_COMMIT = process.env.NODE_ENV === 'development'
30export const shared: UserConfig<DefaultTheme.Config> = { 30export const shared: UserConfig<DefaultTheme.Config> = {
31 ...siteConfig, 31 ...siteConfig,
32 transformHead: async (context) => generateMeta(context, hostname), 32 transformHead: async (context) => generateMeta(context, hostname),
33 transformHtml: async (html, _id, ctx) => {
34 collectPageLinks(html, ctx.page)
35 },
36 buildEnd: async (context) => { 33 buildEnd: async (context) => {
37 writeUrlSearchIndex(context.outDir) 34 writeUrlSearchIndex(context.outDir)
38 if (process.env.CI) { 35 if (process.env.CI) {
@@ -69,6 +66,10 @@ export const shared: UserConfig<DefaultTheme.Config> = {
69 } 66 }
70 } 67 }
71 }, 68 },
69 _render(src, env, md) {
70 collectPageLinks(src, env.relativePath)
71 return md.render(src, env)
72 },
72 detailedView: true 73 detailedView: true
73 }, 74 },
74 provider: 'local' 75 provider: 'local'
docs/.vitepress/plugins/urlSearchPlugin.ts +44 −40
@@ -9,58 +9,63 @@ export interface PageLink {
9 titles: string[] 9 titles: string[]
10} 10}
11 11
12function stripTags(html: string): string { 12function extractLinksFromMarkdown(src: string, pageId: string): PageLink[] {
13 return html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim()
14}
15
16function decodeEntities(s: string): string {
17 return s
18 .replace(/&amp;/g, '&')
19 .replace(/&lt;/g, '<')
20 .replace(/&gt;/g, '>')
21 .replace(/&quot;/g, '"')
22 .replace(/&#39;/g, "'")
23}
24
25function extractLinks(html: string, pageId: string): PageLink[] {
26 const results: PageLink[] = [] 13 const results: PageLink[] = []
27 const seen = new Set<string>() 14 const seen = new Set<string>()
28 const headingStack: string[] = [] 15 const headingStack: string[] = []
29 let currentAnchor = '' 16 let currentAnchor = ''
30 17
31 const tagRE = /<(h[1-6]|a)\b([^>]*)>([^<]*)/gi 18 // Strip frontmatter
32 let m: RegExpExecArray | null 19 const body = src.startsWith('---')
20 ? src.replace(/^---[\s\S]*?---\n?/, '')
21 : src
33 22
34 while ((m = tagRE.exec(html)) !== null) { 23 for (const line of body.split('\n')) {
35 const [, tag, attrs, text] = m 24 // Heading: ## Title or === Title (setext-style ignored, ATX only)
36 const tagLower = tag.toLowerCase() 25 const headingMatch = line.match(/^(#{1,6})\s+(.+)/)
37 26 if (headingMatch) {
38 if (/^h[1-6]$/.test(tagLower)) { 27 const level = headingMatch[1].length - 1
39 const level = parseInt(tagLower[1]) - 1 28 const text = headingMatch[2].trim()
40 const idMatch = attrs.match(/\bid=["']([^"']*)["']/) 29 headingStack[level] = text
41 if (idMatch) currentAnchor = idMatch[1]
42 const rest = html.slice(tagRE.lastIndex)
43 const closeIdx = rest.search(new RegExp(`</${tagLower}>`, 'i'))
44 const headingHtml = text + (closeIdx >= 0 ? rest.slice(0, closeIdx) : '')
45 headingStack[level] = decodeEntities(stripTags(headingHtml))
46 headingStack.length = level + 1 30 headingStack.length = level + 1
31 // Derive anchor the same way VitePress does: lowercase, spaces→hyphens, strip non-word
32 currentAnchor = text
33 .toLowerCase()
34 .replace(/[^\w\s-]/g, '')
35 .replace(/\s+/g, '-')
36 .replace(/-+/g, '-')
37 .replace(/^-|-$/g, '')
47 continue 38 continue
48 } 39 }
49 40
50 if (tagLower === 'a') { 41 // Markdown links: [text](https://...)
51 const hrefMatch = attrs.match(/\bhref=["']([^"']*)["']/) 42 const linkRE = /\[([^\]]*)\]\((https?:\/\/[^)]+)\)/g
52 if (!hrefMatch) continue 43 let m: RegExpExecArray | null
53 const href = decodeEntities(hrefMatch[1]) 44 while ((m = linkRE.exec(line)) !== null) {
54 if (!/^https?:\/\//i.test(href)) continue 45 const linkText = m[1].trim()
46 const href = m[2].trim()
47 const key = href + '\x00' + currentAnchor
48 if (seen.has(key)) continue
49 seen.add(key)
50 results.push({
51 href,
52 linkText,
53 pageId,
54 anchor: currentAnchor,
55 titles: headingStack.filter(Boolean)
56 })
57 }
58
59 // Bare angle-bracket URLs: <https://...>
60 const bareRE = /<(https?:\/\/[^>]+)>/g
61 while ((m = bareRE.exec(line)) !== null) {
62 const href = m[1].trim()
55 const key = href + '\x00' + currentAnchor 63 const key = href + '\x00' + currentAnchor
56 if (seen.has(key)) continue 64 if (seen.has(key)) continue
57 seen.add(key) 65 seen.add(key)
58 const rest = html.slice(tagRE.lastIndex)
59 const closeIdx = rest.search(/<\/a>/i)
60 const linkHtml = text + (closeIdx >= 0 ? rest.slice(0, closeIdx) : '')
61 results.push({ 66 results.push({
62 href, 67 href,
63 linkText: decodeEntities(stripTags(linkHtml)), 68 linkText: href,
64 pageId, 69 pageId,
65 anchor: currentAnchor, 70 anchor: currentAnchor,
66 titles: headingStack.filter(Boolean) 71 titles: headingStack.filter(Boolean)
@@ -73,10 +78,9 @@ function extractLinks(html: string, pageId: string): PageLink[] {
73 78
74const collected: PageLink[] = [] 79const collected: PageLink[] = []
75 80
76export function collectPageLinks(html: string, page: string) { 81export function collectPageLinks(src: string, page: string) {
77 // page is like "anime/watching.md" (relative to srcDir)
78 const pageId = '/' + page.replace(/\.md$/, '').replace(/\/index$/, '/') 82 const pageId = '/' + page.replace(/\.md$/, '').replace(/\/index$/, '/')
79 collected.push(...extractLinks(html, pageId)) 83 collected.push(...extractLinksFromMarkdown(src, pageId))
80} 84}
81 85
82export function writeUrlSearchIndex(outDir: string) { 86export function writeUrlSearchIndex(outDir: string) {
docs/.vitepress/theme/components/Search.vue +61 −115
@@ -1,8 +1,9 @@
1<script lang="ts" setup> 1<script lang="ts" setup>
2import MiniSearch, { type SearchResult } from 'minisearch' 2import MiniSearch, { type SearchResult } from 'minisearch'
3import { type DefaultTheme, inBrowser, useRouter } from 'vitepress' 3import { type DefaultTheme, dataSymbol, inBrowser, useRouter } from 'vitepress'
4import { 4import {
5 computed, 5 computed,
6 createApp,
6 markRaw, 7 markRaw,
7 nextTick, 8 nextTick,
8 onBeforeUnmount, 9 onBeforeUnmount,
@@ -642,6 +643,10 @@ watchDebounced(
642 } 643 }
643 } 644 }
644 645
646 // Show results immediately (excerpts may be empty on first detail-view switch;
647 // they fill in below once built)
648 results.value = toRows(_result)
649
645 if (showDetailedListValue) { 650 if (showDetailedListValue) {
646 const eagerDocs = new Set<string>() 651 const eagerDocs = new Set<string>()
647 for (const r of _result.slice(0, EAGER_EXCERPTS)) { 652 for (const r of _result.slice(0, EAGER_EXCERPTS)) {
@@ -1236,22 +1241,24 @@ function onMouseMove(e: MouseEvent) {
1236 class="results" 1241 class="results"
1237 @mousemove="onMouseMove" 1242 @mousemove="onMouseMove"
1238 > 1243 >
1239 <!-- URL search mode results --> 1244 <!-- Empty state (shared) -->
1245 <div
1246 v-if="urlSearchMode
1247 ? (!filterText || !urlResults.length)
1248 : (!filterText || !filteredResults.length)"
1249 class="flex flex-col justify-center items-center h-47.5 gap-2 font-medium text-sm text-gray-500 dark:text-gray-300 m-auto md:mt-10 md:mb-6 opacity-90"
1250 >
1251 <img
1252 class="h-40 object-contain object-center -translate-x-2"
1253 src="/asset/smolame.png"
1254 alt="Smol ame"
1255 />
1256 <h1 v-if="filterText">Couldn't find anything, try again?</h1>
1257 <h1 v-else>Looking for something?</h1>
1258 </div>
1259
1260 <!-- URL search results -->
1240 <template v-if="urlSearchMode"> 1261 <template v-if="urlSearchMode">
1241 <div
1242 class="flex flex-col justify-center items-center h-47.5 gap-2 font-medium text-sm text-gray-500 dark:text-gray-300 m-auto md:mt-10 md:mb-6 opacity-90"
1243 v-if="!filterText || (filterText && !urlResults.length)"
1244 >
1245 <img
1246 class="h-40 object-contain object-center -translate-x-2"
1247 src="/asset/smolame.png"
1248 alt="Smol ame"
1249 />
1250 <h1 v-if="filterText && !urlResults.length">
1251 Couldn't find anything, try again?
1252 </h1>
1253 <h1 v-else>Looking for something?</h1>
1254 </div>
1255 <li 1262 <li
1256 v-for="(item, index) in filteredUrlResults" 1263 v-for="(item, index) in filteredUrlResults"
1257 :key="item.href + item.pageId" 1264 :key="item.href + item.pageId"
@@ -1262,7 +1269,7 @@ function onMouseMove(e: MouseEvent) {
1262 > 1269 >
1263 <a 1270 <a
1264 :href="item.anchor ? item.pageId + '#' + item.anchor : item.pageId" 1271 :href="item.anchor ? item.pageId + '#' + item.anchor : item.pageId"
1265 class="result url-result" 1272 class="result"
1266 :class="{ selected: selectedIndex === index + 1 }" 1273 :class="{ selected: selectedIndex === index + 1 }"
1267 :aria-label="item.linkText || item.href" 1274 :aria-label="item.linkText || item.href"
1268 @mouseenter="!disableMouseOver && (selectedIndex = index + 1)" 1275 @mouseenter="!disableMouseOver && (selectedIndex = index + 1)"
@@ -1270,36 +1277,33 @@ function onMouseMove(e: MouseEvent) {
1270 @click="onResultClick" 1277 @click="onResultClick"
1271 :data-index="index + 1" 1278 :data-index="index + 1"
1272 > 1279 >
1273 <div class="url-result-content"> 1280 <div>
1274 <div> 1281 <div class="titles">
1275 <div class="titles"> 1282 <Hash v-if="item.titles.length > 0" stroke-width="1.25" :size="18" />
1276 <Hash v-if="item.titles.length > 0" stroke-width="1.25" :size="18" /> 1283 <File v-else stroke-width="1.25" :size="18" />
1277 <File v-else stroke-width="1.25" :size="18" /> 1284 <span
1278 <span 1285 v-for="(t, ti) in item.titles"
1279 v-for="(t, ti) in item.titles" 1286 :key="ti"
1280 :key="ti" 1287 class="title"
1281 class="title" 1288 >
1282 > 1289 <span class="text" v-html="t" />
1283 <span class="text" v-html="t" /> 1290 <ArrowRight stroke-width="1.25" :size="18" class="mx-0.5" />
1284 <ArrowRight stroke-width="1.25" :size="18" class="mx-0.5" /> 1291 </span>
1285 </span> 1292 <span class="title main">
1286 <span class="title main"> 1293 <span class="text">{{ item.linkText || item.href }}</span>
1287 <span class="text">{{ item.linkText || item.href }}</span> 1294 </span>
1288 </span> 1295 <a
1289 </div> 1296 :href="item.href"
1290 1297 target="_blank"
1298 rel="noopener noreferrer"
1299 class="url-open-btn"
1300 :class="{ 'url-open-btn-selected': selectedIndex === index + 1 }"
1301 title="Open link"
1302 @click.stop
1303 >
1304 <ExternalLink :size="14" stroke-width="1.5" />
1305 </a>
1291 </div> 1306 </div>
1292 <a
1293 :href="item.href"
1294 target="_blank"
1295 rel="noopener noreferrer"
1296 class="url-open-btn"
1297 :class="{ 'url-open-btn-selected': selectedIndex === index + 1 }"
1298 title="Open link"
1299 @click.stop
1300 >
1301 <ExternalLink :size="14" stroke-width="1.5" />
1302 </a>
1303 </div> 1307 </div>
1304 </a> 1308 </a>
1305 </li> 1309 </li>
@@ -1307,22 +1311,7 @@ function onMouseMove(e: MouseEvent) {
1307 1311
1308 <!-- Normal search results --> 1312 <!-- Normal search results -->
1309 <template v-else> 1313 <template v-else>
1310 <div 1314 <li
1311 class="flex flex-col justify-center items-center h-47.5 gap-2 font-medium text-sm text-gray-500 dark:text-gray-300 m-auto md:mt-10 md:mb-6 opacity-90"
1312 v-if="!filterText || (filterText && !filteredResults.length)"
1313 >
1314 <img
1315 class="h-40 object-contain object-center -translate-x-2"
1316 src="/asset/smolame.png"
1317 alt="Smol ame"
1318 />
1319 <h1 v-if="filterText && !filteredResults.length">
1320 Couldn't find anything, try again?
1321 </h1>
1322 <h1 v-else>Looking for something?</h1>
1323 </div>
1324
1325 <li
1326 v-for="(p, index) in filteredResults" 1315 v-for="(p, index) in filteredResults"
1327 :key="p.id" 1316 :key="p.id"
1328 class="result-layout" 1317 class="result-layout"
@@ -1333,36 +1322,24 @@ function onMouseMove(e: MouseEvent) {
1333 <a 1322 <a
1334 :href="p.id" 1323 :href="p.id"
1335 class="result" 1324 class="result"
1336 :class="{ 1325 :class="{ selected: selectedIndex === index + 1 }"
1337 selected: selectedIndex === index + 1
1338 }"
1339 :aria-label="[...p.titles, p.title].join(' > ')" 1326 :aria-label="[...p.titles, p.title].join(' > ')"
1340 @mouseenter="!disableMouseOver && 1327 @mouseenter="!disableMouseOver && (selectedIndex = index + 1)"
1341 (selectedIndex = index + 1)"
1342 @focusin="selectedIndex = index + 1" 1328 @focusin="selectedIndex = index + 1"
1343 @click="onResultClick" 1329 @click="onResultClick"
1344 :data-index="index + 1" 1330 :data-index="index + 1"
1345 > 1331 >
1346 <div> 1332 <div>
1347 <div class="titles"> 1333 <div class="titles">
1348 <Hash 1334 <Hash v-if="p.titles.length > 0" stroke-width="1.25" :size="18" />
1349 v-if="p.titles.length > 0"
1350 stroke-width="1.25"
1351 :size="18"
1352 />
1353 <File v-else stroke-width="1.25" :size="18" /> 1335 <File v-else stroke-width="1.25" :size="18" />
1354
1355 <span 1336 <span
1356 v-for="(t, index) in p.titles" 1337 v-for="(t, index) in p.titles"
1357 :key="index" 1338 :key="index"
1358 class="title" 1339 class="title"
1359 > 1340 >
1360 <span class="text" v-html="t" /> 1341 <span class="text" v-html="t" />
1361 <ArrowRight 1342 <ArrowRight stroke-width="1.25" :size="18" class="mx-0.5" />
1362 stroke-width="1.25"
1363 :size="18"
1364 class="mx-0.5"
1365 />
1366 </span> 1343 </span>
1367 <span class="title main"> 1344 <span class="title main">
1368 <span class="text" v-html="p.title" /> 1345 <span class="text" v-html="p.title" />
@@ -1370,11 +1347,7 @@ function onMouseMove(e: MouseEvent) {
1370 </div> 1347 </div>
1371 1348
1372 <div v-if="showDetailedList" class="excerpt-wrapper"> 1349 <div v-if="showDetailedList" class="excerpt-wrapper">
1373 <div 1350 <div v-if="p.text" class="excerpt" inert>
1374 v-if="p.text"
1375 class="excerpt"
1376 inert
1377 >
1378 <div class="vp-doc" v-html="p.text" /> 1351 <div class="vp-doc" v-html="p.text" />
1379 </div> 1352 </div>
1380 <div class="excerpt-gradient-bottom" /> 1353 <div class="excerpt-gradient-bottom" />
@@ -1383,7 +1356,7 @@ function onMouseMove(e: MouseEvent) {
1383 </div> 1356 </div>
1384 </a> 1357 </a>
1385 </li> 1358 </li>
1386 </template> 1359 </template>
1387 </ul> 1360 </ul>
1388 1361
1389 <div class="search-keyboard-shortcuts"> 1362 <div class="search-keyboard-shortcuts">
@@ -1918,30 +1891,18 @@ svg {
1918 background: rgba(60, 120, 210, 0.10); 1891 background: rgba(60, 120, 210, 0.10);
1919} 1892}
1920 1893
1921.url-result-content {
1922 display: flex;
1923 align-items: center;
1924 width: 100%;
1925 gap: 8px;
1926}
1927
1928.url-result-content > div:first-child {
1929 flex: 1;
1930 min-width: 0;
1931}
1932
1933.url-open-btn { 1894.url-open-btn {
1934 flex: none; 1895 flex: none;
1935 display: flex; 1896 display: flex;
1936 align-items: center; 1897 align-items: center;
1937 justify-content: center; 1898 justify-content: center;
1938 width: 28px; 1899 width: 24px;
1939 height: 28px; 1900 height: 24px;
1940 border-radius: 6px; 1901 border-radius: 4px;
1941 color: var(--vp-c-text-3); 1902 color: var(--vp-c-text-3);
1942 opacity: 0; 1903 opacity: 0;
1943 transition: opacity 0.15s, color 0.15s, background 0.15s; 1904 transition: opacity 0.15s, color 0.15s, background 0.15s;
1944 margin-right: 4px; 1905 margin-left: auto;
1945} 1906}
1946 1907
1947.result:hover .url-open-btn, 1908.result:hover .url-open-btn,
@@ -1964,21 +1925,6 @@ svg {
1964 color: var(--vp-c-brand-1) !important; 1925 color: var(--vp-c-brand-1) !important;
1965} 1926}
1966 1927
1967.url-excerpt {
1968 height: auto !important;
1969 max-height: none !important;
1970 overflow: visible !important;
1971}
1972
1973.url-excerpt-href {
1974 font-size: 0.78rem !important;
1975 font-family: var(--vp-font-family-mono, monospace);
1976 color: var(--vp-c-text-2);
1977 word-break: break-all;
1978 line-height: 1.5;
1979 padding: 2px 0;
1980}
1981
1982:deep(.url-highlight) { 1928:deep(.url-highlight) {
1983 background-color: var(--vp-local-search-highlight-bg); 1929 background-color: var(--vp-local-search-highlight-bg);
1984 color: var(--vp-local-search-highlight-text); 1930 color: var(--vp-local-search-highlight-text);