Commit 66fac86788

66fac8678823448ec8d443efe31b8a97afa1b66e

parent: 248ed403e7

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-05-30 13:47 UTC

meme

Layout: unified · split

docs/.vitepress/configs/index.ts +26 −1
@@ -44,6 +44,31 @@ export const shared: UserConfig<DefaultTheme.Config> = {
4444 search: {
4545 options: {
4646 miniSearch: {
47 _render(src, env, md) {
48 const html = md.render(src, env)
49 if (env.frontmatter?.search === false) return html
50 const BARE_TLDS = new Set([
51 'org', 'com', 'net', 'io', 'co', 'gg', 'tv', 'me', 'app',
52 'dev', 'xyz', 'info', 'moe', 'to', 'cc', 'fm', 'fr', 'jp'
53 ])
54 const seen = new Set<string>()
55 for (const m of html.matchAll(/href="([^"]+)"/g)) {
56 try {
57 const u = new URL(m[1])
58 const host = u.hostname.replace(/^www\./, '')
59 if (!host) continue
60 seen.add(host)
61 const bare = host.split('.')[0]
62 if (bare && !BARE_TLDS.has(bare)) seen.add(bare)
63 } catch {
64 }
65 }
66 for (const t of [...seen]) if (BARE_TLDS.has(t)) seen.delete(t)
67 if (seen.size === 0) return html
68 return `${html}\n<p class="vp-search-urls" aria-hidden="true" style="display:none">${
69 [...seen].join(' ')
70 }</p>`
71 },
4772 searchOptions: {
4873 combineWith: 'AND',
4974 fuzzy: false,
@@ -148,4 +173,4 @@ export const shared: UserConfig<DefaultTheme.Config> = {
148173 ]
149174 }
150175 }
151}
176}
\ No newline at end of file
docs/.vitepress/theme/components/Search.vue +26 −2
@@ -203,8 +203,15 @@ watchDebounced(
203203 if (!index) return
204204
205205 // Search
206 const isUrlQuery = looksLikeUrl(filterTextValue)
207 const queryForSearch = isUrlQuery
208 ? normalizeUrlQuery(filterTextValue)
209 : filterTextValue
206210 const _result = index
207 .search(filterTextValue)
211 .search(
212 queryForSearch,
213 isUrlQuery ? { combineWith: 'OR' } : undefined
214 )
208215 .slice(0, 16) as (SearchResult & Result)[]
209216 enableNoResults.value = true
210217
@@ -552,6 +559,23 @@ watch(
552559 }
553560)
554561
562function looksLikeUrl(query: string) {
563 return /https?:\/\/|www\.|[^\s]+\.[a-z]{2,}(\/|$)/i.test(query.trim())
564}
565
566function normalizeUrlQuery(query: string) {
567 const cleaned = query
568 .trim()
569 .replace(/^https?:\/\//i, '')
570 .replace(/^www\./i, '')
571 .replace(/[?#].*$/, '')
572 .replace(/\/.*$/, '') // drop path, keep host only
573 const host = cleaned.trim()
574 if (!host) return query.trim()
575 const bareName = host.split('.')[0]
576 return bareName && bareName !== host ? `${host} ${bareName}` : host
577}
578
555579function formMarkRegex(terms: Set<string>) {
556580 return new RegExp(
557581 [...terms]
@@ -1208,4 +1232,4 @@ svg {
12081232 background-color: rgba(var(--vp-c-brand-1), 0.1);
12091233 border-radius: 4px;
12101234}
1211</style>
1235</style>
\ No newline at end of file