Skip to content

Commit f0e0880

Browse files
committed
feat: 文档搜索改用MiniSearch
1 parent c037658 commit f0e0880

File tree

9 files changed

+243
-12
lines changed

9 files changed

+243
-12
lines changed

docs/.vitepress/config.mts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,34 @@ export default defineConfig({
179179
message: "Released under the MIT License.",
180180
copyright: "Copyright © 2021-present Renn Cheung"
181181
},
182+
search: {
183+
provider: 'local',
184+
options: {
185+
locales: {
186+
"zh-CN": {
187+
translations: {
188+
button: {
189+
buttonText: '搜索文档',
190+
buttonAriaLabel: '搜索文档'
191+
},
192+
modal: {
193+
noResultsText: '无法找到相关结果',
194+
resetButtonTitle: '清除查询条件',
195+
footer: {
196+
selectText: '选择',
197+
navigateText: '切换'
198+
}
199+
}
200+
}
201+
}
202+
}
203+
}
204+
},
182205

183-
algolia: {
184-
appId: "TIA2QKB31F",
185-
apiKey: "57dd54cc00e988117cc8b741128f5089",
186-
indexName: "codemirror-editor-vue3"
187-
}
206+
// algolia: {
207+
// appId: "TIA2QKB31F",
208+
// apiKey: "57dd54cc00e988117cc8b741128f5089",
209+
// indexName: "codemirror-editor-vue3"
210+
// }
188211
}
189212
})
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<template>
2+
<Codemirror
3+
v-model:value="code"
4+
:options="cmOptions"
5+
:height="300"
6+
width="80%"
7+
class="cm-component"
8+
:border="true"
9+
@ready="onReady"
10+
/>
11+
</template>
12+
<script lang="ts" setup>
13+
import { ref, reactive, watch } from "vue";
14+
import { Editor, EditorConfiguration } from "codemirror";
15+
import Codemirror from "codemirror-editor-vue3";
16+
// language
17+
// import "codemirror/mode/javascript/javascript.js";
18+
// // import "codemirror/mode/clike/clike.js";
19+
// import "codemirror/addon/lint/javascript-lint";
20+
// import "codemirror/addon/lint/lint.css";
21+
// import "codemirror/addon/lint/lint.js";
22+
// import "codemirror/addon/lint/json-lint";
23+
24+
const code = ref(`function findSequence(goal) {
25+
function find(start, history) {
26+
if (start == goal)
27+
return history;
28+
else if (start > goal)
29+
return null;
30+
else
31+
return find(start + 5, "(" + history + " + 5)") ||
32+
find(start * 3, "(" + history + " * 3)");
33+
}
34+
return find(1, "1");
35+
}`);
36+
37+
const props = defineProps<{
38+
lang: string;
39+
}>();
40+
41+
watch(() => props.lang, (lang) => {
42+
import("codemirror/mode/clike/clike.js");
43+
console.log(lang);
44+
}, {
45+
immediate: true,
46+
});
47+
const cmOptions:EditorConfiguration = reactive({
48+
mode: props.lang,
49+
// mode: "application/json",
50+
lineNumbers: true,
51+
lineWiseCopyCut: true,
52+
// gutters: ["CodeMirror-lint-markers"],
53+
});
54+
console.log(" cmOptions", cmOptions);
55+
56+
const cminstance = ref<Editor | null>(null);
57+
const onReady = (cm: Editor) => {
58+
cminstance.value = cm;
59+
console.log(cm.getValue());
60+
};
61+
62+
defineExpose({
63+
setTheme: (theme: string) => {
64+
cminstance.value?.setOption("theme", theme);
65+
},
66+
});
67+
</script>
68+
<style lang="less" scoped>
69+
.cm-component {
70+
font-family: monospace;
71+
}
72+
</style>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<div> Basic Demo</div>
3+
<Example
4+
:schema="{
5+
raw: jsDemoRaw,
6+
comp: jsDemo,
7+
describe: 'javascript 模式下可展示 json 数据',
8+
lang: 'javascript',
9+
props: {
10+
lang: 'text/x-c',
11+
}
12+
}"
13+
/>
14+
</template>
15+
16+
<script lang="ts" setup>
17+
import Example from "../components/Example.vue";
18+
import jsDemo from "./demo.vue";
19+
import jsDemoRaw from "./demo.vue?raw";
20+
21+
</script>
22+
23+
<style scoped lang="less"></style>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<template>
2+
<div class="vp-code-group vp-adaptive-theme">
3+
<div class="tabs">
4+
<input
5+
id="tab-JFiS9vo"
6+
type="radio"
7+
name="group-Qis5R"
8+
checked="checked"
9+
><label
10+
for="tab-JFiS9vo"
11+
@click="type = 'npm'"
12+
>npm</label><input
13+
id="tab-NQHnuSp"
14+
type="radio"
15+
name="group-Qis5R"
16+
><label
17+
for="tab-NQHnuSp"
18+
@click="type = 'yarn'"
19+
>yarn</label><input
20+
id="tab-S4PgNg6"
21+
type="radio"
22+
name="group-Qis5R"
23+
><label
24+
for="tab-S4PgNg6"
25+
@click="type = 'pnpm'"
26+
>pnpm</label>
27+
</div>
28+
<div class="blocks">
29+
<div class="language-bash vp-adaptive-theme active">
30+
<button
31+
title="Copy Code"
32+
class="copy"
33+
/>
34+
<span class="lang">bash</span>
35+
<div
36+
class="shiki shiki-themes github-light github-dark vp-code py-5 px-20px text-14px"
37+
>
38+
<span class="line">
39+
<span
40+
style="--shiki-light: #6f42c1; --shiki-dark: #b392f0"
41+
class="mr-8px"
42+
>{{ type }}
43+
</span>
44+
<span
45+
style="--shiki-light: #032f62; --shiki-dark: #9ecbff"
46+
class="mr-8px"
47+
>
48+
{{ typeCommadnMap[type] }}
49+
</span>
50+
<span
51+
v-for="(item,index) in props.deps"
52+
:key="index"
53+
class="mr-8px"
54+
style="--shiki-light: #032f62; --shiki-dark: #9ecbff"
55+
> {{ item }}</span>
56+
</span>
57+
</div>
58+
</div>
59+
</div>
60+
</div>
61+
</template>
62+
63+
<script lang="ts" setup>
64+
import { ref, watchEffect } from "vue";
65+
66+
const props = defineProps<{
67+
deps: string[];
68+
}>();
69+
70+
const type = ref("npm");
71+
const typeCommadnMap = {
72+
npm: "install",
73+
yarn: "add",
74+
pnpm: "add",
75+
};
76+
77+
</script>
78+
79+
<style scoped lang="less">
80+
.line span {
81+
white-space: pre;
82+
font-family: var(--vp-font-family-mono);
83+
}
84+
</style>

docs/demo/examples/components/Example.vue

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<template>
2+
<div
3+
v-if="props.schema?.deps?.length"
4+
class="mt-5"
5+
>
6+
该功能必须安装以下依赖 / Please install the following dependencies:
7+
<BashBlock :deps="props.schema.deps" />
8+
</div>
29
<div class="example">
310
<div class="example-showcase">
411
<div class="w-full mb-5">
@@ -17,6 +24,7 @@
1724
<component
1825
:is="props.schema.comp"
1926
ref="demoRef"
27+
v-bind="props.schema.props"
2028
/>
2129
</div>
2230
<div class="example-action">
@@ -47,14 +55,15 @@
4755

4856
<script lang="ts" setup>
4957
import {
50-
ref, defineProps, computed, watch,
58+
ref, defineProps, computed, watch, nextTick,
5159
} from "vue";
5260
import { useClipboard } from "@vueuse/core";
5361
import VCodeBlock from "@wdns/vue-code-block";
5462
import { useData } from "vitepress";
5563
5664
import IconCopy from "./IconCopy.vue";
5765
import IconCode from "./IconCode.vue";
66+
import BashBlock from "./BashBlock.vue";
5867
5968
// theme
6069
import "codemirror/theme/dracula.css";
@@ -64,8 +73,10 @@ const props = defineProps<{
6473
describe?: string;
6574
lang: string;
6675
raw: string;
67-
comp: any
68-
},
76+
comp: any,
77+
deps?: string[];
78+
props: any
79+
}
6980
}>();
7081
7182
const { isDark } = useData();
@@ -80,8 +91,10 @@ const demoRef = ref<any>(null);
8091
8192
watch(() => [isDark, demoRef], ([val, cmRef]) => {
8293
if (!cmRef.value) return;
83-
cmRef.value?.setTheme(val.value ? "dracula" : "default");
84-
theme.value = val.value ? "github-dark" : "github";
94+
nextTick(() => {
95+
cmRef.value?.setTheme(val.value ? "dracula" : "default");
96+
theme.value = val.value ? "github-dark" : "github";
97+
});
8598
}, { immediate: true, deep: true });
8699
87100
</script>

docs/demo/examples/lint/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ const schemas = [
2626
comp: defineAsyncComponent(() => import("./jsLint.vue")),
2727
describe: "校验 js 代码, 在任意位置输入字符尝试校验功能",
2828
lang: "javascript",
29+
deps: ["jslint"],
2930
},
3031
{
3132
raw: jsonLintRaw,
3233
comp: defineAsyncComponent(() => import("./jsonLint.vue")),
3334
describe: "校验 json 数据, 在任意位置输入字符尝试校验功能",
3435
lang: "application/json",
36+
deps: ["jsonlint"],
3537
},
3638
];
3739

docs/demo/examples/lint/jsonLint.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const onReady = (cm: Editor) => {
7979
8080
defineExpose({
8181
setTheme: (theme: string) => {
82+
console.log(" theme", theme);
8283
cminstance.value?.setOption("theme", theme);
8384
},
8485
});

docs/example/index.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ aside: false
66

77
More cases are being updated...
88

9+
# Interactive Example
10+
11+
::: tip
12+
You can get rich examples through the following configurations.
13+
14+
:::
915

1016
<component v-if="CaseContainer" :is="CaseContainer"></component>
1117

@@ -20,7 +26,7 @@ export default {
2026
},
2127

2228
mounted() {
23-
import('../demo/examples/index.vue').then((module) => {
29+
import('../demo/examples/Interactive/index.vue').then((module) => {
2430
this.CaseContainer = shallowRef(module.default)
2531
})
2632

docs/zh-CN/example/index.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
aside: false
33
---
44

5+
# 交互案例
6+
7+
::: tip
8+
通过下面的各项配置,你可以得到丰富的案例
9+
10+
:::
11+
512
<component v-if="CaseContainer" :is="CaseContainer"></component>
613

714
<script>
@@ -15,7 +22,7 @@ export default {
1522
},
1623

1724
mounted() {
18-
import('../../demo/examples/index.vue').then((module) => {
25+
import('../../demo/examples/Interactive/index.vue').then((module) => {
1926
this.CaseContainer = shallowRef(module.default)
2027
})
2128

0 commit comments

Comments
 (0)