Skip to content

Commit b85b1ac

Browse files
U: enable local searcher by v1.6.4-patched ref vuejs/vitepress#5162
1 parent 9d68edc commit b85b1ac

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

.vitepress/config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ export default defineConfig({
8080
forceLocale: false,
8181
},
8282
},
83+
search: {
84+
provider: 'local',
85+
options: {
86+
translations: {
87+
button: {
88+
buttonText: '搜索',
89+
buttonAriaLabel: '搜索文档'
90+
},
91+
modal: {
92+
displayDetails: '显示详细列表',
93+
noResultsText: '没有结果',
94+
backButtonTitle: '关闭搜索',
95+
resetButtonTitle: '重置搜索',
96+
footer: {
97+
selectText: '选择',
98+
selectKeyAriaLabel: '输入',
99+
navigateText: '导航',
100+
navigateUpKeyAriaLabel: '上箭头',
101+
navigateDownKeyAriaLabel: '下箭头',
102+
closeText: '关闭',
103+
},
104+
},
105+
},
106+
},
107+
},
83108
nav: [
84109
{
85110
text: '指南',

.vitepress/theme/custom.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
--im-feature-shadow: rgba(0, 0, 0, 0.1);
7979
--im-feature-shadow-hover: rgba(0, 0, 0, 0.3);
8080
--vp-c-bg-soft: rgba(255, 255, 245, .6);
81+
--vp-c-bg-alt: transparent;
8182
background: linear-gradient(-40deg, var(--im-gradient-p1), var(--im-gradient-p2), var(--im-gradient-p3), var(--im-gradient-p4));
8283
background-size: 120% 120%;
8384
--vp-c-bg: transparent;

.vitepress/vitepress+1.6.4.patch

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/node_modules/vitepress/dist/node/chunk-D3CUZ4fa.js b/node_modules/vitepress/dist/node/chunk-D3CUZ4fa.js
2-
index fcc35e8..c3fba2b 100644
2+
index fcc35e8..29df7d4 100644
33
--- a/node_modules/vitepress/dist/node/chunk-D3CUZ4fa.js
44
+++ b/node_modules/vitepress/dist/node/chunk-D3CUZ4fa.js
55
@@ -35149,16 +35149,17 @@ function createContainer(klass, defaultTitle, md) {
@@ -38,3 +38,43 @@ index fcc35e8..c3fba2b 100644
3838
};
3939
if (options.gfmAlerts !== false) {
4040
md.use(gitHubAlertsPlugin);
41+
@@ -40453,11 +40458,14 @@ async function localSearchPlugin(siteConfig) {
42+
const env = { path: file, relativePath, cleanUrls };
43+
const md_raw = await fs.promises.readFile(file, "utf-8");
44+
const md_src = processIncludes(srcDir, md_raw, file, []);
45+
- if (options._render) return await options._render(md_src, env, md);
46+
+ let html;
47+
+ if (options._render) html = await options._render(md_src, env, md);
48+
else {
49+
- const html = md.render(md_src, env);
50+
- return env.frontmatter?.search === false ? "" : html;
51+
+ html = md.render(md_src, env);
52+
+ if (env.frontmatter?.search === false) return "";
53+
}
54+
+ if (env.frontmatter) html = resolveFrontmatterExpressions(html, env.frontmatter);
55+
+ return html;
56+
}
57+
const indexByLocales = /* @__PURE__ */ new Map();
58+
function getIndexByLocale(locale) {
59+
@@ -40617,6 +40625,21 @@ function getSearchableText(content) {
60+
function clearHtmlTags(str) {
61+
return str.replace(/<[^>]*>/g, "");
62+
}
63+
+function resolveFrontmatterExpressions(html, frontmatter) {
64+
+ return html.replace(
65+
+ /\{\{\s*\$frontmatter\.(\S+?)\s*\}\}/g,
66+
+ (match, key) => {
67+
+ const value = key
68+
+ .split('.')
69+
+ .reduce(
70+
+ (object, key) => (object != null ? object[key] : undefined),
71+
+ frontmatter
72+
+ )
73+
+
74+
+ return value != null ? String(value) : match
75+
+ }
76+
+ );
77+
+}
78+
79+
var utils$2 = {};
80+

0 commit comments

Comments
 (0)