Commit e246f7483a
Unsigned
Layout: unified · split
docs/.vitepress/configs/index.ts +15 −17
| @@ -10,6 +10,7 @@ import { | ||
| 10 | 10 | PagePropertiesMarkdownSection |
| 11 | 11 | } from '@nolebase/vitepress-plugin-page-properties/vite' |
| 12 | 12 | import { fileURLToPath, URL } from 'node:url' |
| 13 | import { parse as parseDomain } from 'tldts' | |
| 13 | 14 | import UnoCSS from 'unocss/vite' |
| 14 | 15 | import Devtools from 'vite-plugin-vue-devtools' |
| 15 | 16 | import type { DefaultTheme, Plugin, UserConfig } from 'vitepress' |
| @@ -28,6 +29,10 @@ const GIT_COMMIT = process.env.NODE_ENV === 'development' | ||
| 28 | 29 | .then((result) => result.stdout.trim())) ?? |
| 29 | 30 | 'dev') |
| 30 | 31 | |
| 32 | function siteName(host: string): string { | |
| 33 | return parseDomain(host).domainWithoutSuffix ?? '' | |
| 34 | } | |
| 35 | ||
| 31 | 36 | export const shared: UserConfig<DefaultTheme.Config> = { |
| 32 | 37 | ...siteConfig, |
| 33 | 38 | transformHead: async (context) => generateMeta(context, hostname), |
| @@ -44,30 +49,23 @@ export const shared: UserConfig<DefaultTheme.Config> = { | ||
| 44 | 49 | search: { |
| 45 | 50 | options: { |
| 46 | 51 | 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 | ]) | |
| 52 | async _render(src, env, md) { | |
| 53 | const html = await md.renderAsync(src, env) | |
| 54 | if (env.frontmatter?.search === false) return '' | |
| 54 | 55 | const seen = new Set<string>() |
| 55 | 56 | for (const m of html.matchAll(/href="([^"]+)"/g)) { |
| 56 | 57 | try { |
| 57 | const u = new URL(m[1]) | |
| 58 | const host = u.hostname.replace(/^www\./, '') | |
| 58 | const host = new URL(m[1]).hostname.replace(/^www\./, '') | |
| 59 | 59 | if (!host) continue |
| 60 | 60 | seen.add(host) |
| 61 | const bare = host.split('.')[0] | |
| 62 | if (bare && !BARE_TLDS.has(bare)) seen.add(bare) | |
| 63 | } catch { | |
| 64 | } | |
| 61 | const name = siteName(host) | |
| 62 | if (name) seen.add(name) | |
| 63 | } catch {} | |
| 65 | 64 | } |
| 66 | for (const t of [...seen]) if (BARE_TLDS.has(t)) seen.delete(t) | |
| 67 | 65 | 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>` | |
| 66 | return `${html}\n<p class="vp-search-urls" aria-hidden="true" style="display:none">${[ | |
| 67 | ...seen | |
| 68 | ].join(' ')}</p>` | |
| 71 | 69 | }, |
| 72 | 70 | searchOptions: { |
| 73 | 71 | combineWith: 'AND', |
docs/.vitepress/theme/components/Search.vue +6 −7
| @@ -210,7 +210,9 @@ watchDebounced( | ||
| 210 | 210 | const _result = index |
| 211 | 211 | .search( |
| 212 | 212 | queryForSearch, |
| 213 | isUrlQuery ? { combineWith: 'OR' } : undefined | |
| 213 | isUrlQuery | |
| 214 | ? { combineWith: 'AND', prefix: false, fuzzy: false } | |
| 215 | : undefined | |
| 214 | 216 | ) |
| 215 | 217 | .slice(0, 16) as (SearchResult & Result)[] |
| 216 | 218 | enableNoResults.value = true |
| @@ -564,16 +566,13 @@ function looksLikeUrl(query: string) { | ||
| 564 | 566 | } |
| 565 | 567 | |
| 566 | 568 | function normalizeUrlQuery(query: string) { |
| 567 | const cleaned = query | |
| 569 | return query | |
| 568 | 570 | .trim() |
| 569 | 571 | .replace(/^https?:\/\//i, '') |
| 570 | 572 | .replace(/^www\./i, '') |
| 571 | 573 | .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 | |
| 574 | .replace(/\/.*$/, '') | |
| 575 | .trim() | |
| 577 | 576 | } |
| 578 | 577 | |
| 579 | 578 | function formMarkRegex(terms: Set<string>) { |
package.json +1
| @@ -45,6 +45,7 @@ | ||
| 45 | 45 | "reka-ui": "^2.6.0", |
| 46 | 46 | "takumi-js": "^1.1.2", |
| 47 | 47 | "tinyexec": "^1.0.1", |
| 48 | "tldts": "^7.4.2", | |
| 48 | 49 | "ufo": "^1.6.1", |
| 49 | 50 | "unocss": "66.5.5", |
| 50 | 51 | "vite": "^7.2.2", |
pnpm-lock.yaml +16 −5
| @@ -104,6 +104,9 @@ importers: | ||
| 104 | 104 | tinyexec: |
| 105 | 105 | specifier: ^1.0.1 |
| 106 | 106 | version: 1.0.2 |
| 107 | tldts: | |
| 108 | specifier: ^7.4.2 | |
| 109 | version: 7.4.2 | |
| 107 | 110 | ufo: |
| 108 | 111 | specifier: ^1.6.1 |
| 109 | 112 | version: 1.6.1 |
| @@ -3314,6 +3317,13 @@ packages: | ||
| 3314 | 3317 | resolution: {integrity: sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==} |
| 3315 | 3318 | engines: {node: '>=12.0.0'} |
| 3316 | 3319 | |
| 3320 | tldts-core@7.4.2: | |
| 3321 | resolution: {integrity: sha512-nwEyF4vl4RSJjwSjBUmOSxc3BFPoIFdlRthJ6e+5v9P3bHNsoD06UjuqMUspqp7vsEZ1beaHi1km+optiE17yA==} | |
| 3322 | ||
| 3323 | tldts@7.4.2: | |
| 3324 | resolution: {integrity: sha512-kCwffuaH8ntKtygnWe1b4BJKWiCUH30n5KfoTr6IchcXOwR7chAOFJxFrH3vjANafUYrIA4a7SDL+nn7SiR4Sw==} | |
| 3325 | hasBin: true | |
| 3326 | ||
| 3317 | 3327 | to-regex-range@5.0.1: |
| 3318 | 3328 | resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} |
| 3319 | 3329 | engines: {node: '>=8.0'} |
| @@ -3603,9 +3613,6 @@ packages: | ||
| 3603 | 3613 | postcss: |
| 3604 | 3614 | optional: true |
| 3605 | 3615 | |
| 3606 | vscode-uri@3.1.0: | |
| 3607 | resolution: {integrity: sha512-/BpdSx+yCQGnCvecbyXdxHDkuk55/G3xwnC0GqY4gmQ3j+A+g8kzzgB4Nk/SINjqn6+waqw3EgbVF2QKExkRxQ==} | |
| 3608 | ||
| 3609 | 3616 | vue-demi@0.14.10: |
| 3610 | 3617 | resolution: {integrity: sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==} |
| 3611 | 3618 | engines: {node: '>=12'} |
| @@ -6810,6 +6817,12 @@ snapshots: | ||
| 6810 | 6817 | fdir: 6.5.0(picomatch@4.0.3) |
| 6811 | 6818 | picomatch: 4.0.3 |
| 6812 | 6819 | |
| 6820 | tldts-core@7.4.2: {} | |
| 6821 | ||
| 6822 | tldts@7.4.2: | |
| 6823 | dependencies: | |
| 6824 | tldts-core: 7.4.2 | |
| 6825 | ||
| 6813 | 6826 | to-regex-range@5.0.1: |
| 6814 | 6827 | dependencies: |
| 6815 | 6828 | is-number: 7.0.0 |
| @@ -7126,8 +7139,6 @@ snapshots: | ||
| 7126 | 7139 | - universal-cookie |
| 7127 | 7140 | - yaml |
| 7128 | 7141 | |
| 7129 | vscode-uri@3.1.0: {} | |
| 7130 | ||
| 7131 | 7142 | vue-demi@0.14.10(vue@3.5.24(typescript@5.6.3)): |
| 7132 | 7143 | dependencies: |
| 7133 | 7144 | vue: 3.5.24(typescript@5.6.3) |