@sugarat/theme 0.1.37 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -34,15 +34,15 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@mdit-vue/shared": "^0.12.0",
37
+ "@mermaid-js/mermaid-mindmap": "^9.3.0",
37
38
  "@vue/shared": "^3.2.45",
38
39
  "@vueuse/core": "^9.6.0",
39
40
  "fast-glob": "^3.2.12",
40
41
  "gray-matter": "^4.0.3",
41
42
  "highlight.js": "^11.7.0",
42
- "vue-command-palette": "^0.1.4",
43
- "@mermaid-js/mermaid-mindmap": "^9.3.0",
44
43
  "mermaid": "^10.2.4",
45
- "vitepress-plugin-mermaid": "^2.0.13"
44
+ "vitepress-plugin-mermaid": "^2.0.13",
45
+ "vue-command-palette": "^0.1.4"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@element-plus/icons-vue": "^2.1.0",
@@ -56,11 +56,11 @@
56
56
  },
57
57
  "scripts": {
58
58
  "dev": "npm run build:node && npm run dev:docs",
59
- "dev:docs": "vitepress dev demo",
59
+ "dev:docs": "vitepress dev docs",
60
60
  "dev:node": "npx tsup src/node.ts --dts --out-dir=./ --watch",
61
61
  "build": "npm run build:node && npm run build:docs",
62
- "build:docs": "vitepress build demo",
62
+ "build:docs": "vitepress build docs",
63
63
  "build:node": "npx tsup src/node.ts --dts --out-dir=./",
64
- "serve": "vitepress serve demo"
64
+ "serve": "vitepress serve docs"
65
65
  }
66
66
  }
@@ -32,7 +32,7 @@ const { Layout } = Theme
32
32
  <BlogImagePreview />
33
33
  </template>
34
34
 
35
- <!-- 自定义搜索,临时替代Algolia -->
35
+ <!-- 自定义搜索,替代Algolia,未来择机移除 -->
36
36
  <template #nav-bar-content-before>
37
37
  <BlogSearch />
38
38
  </template>
@@ -32,7 +32,7 @@
32
32
  <Command.Group v-else :heading="headingText">
33
33
  <Command.Item
34
34
  v-for="item in searchResult"
35
- :data-value="withBase(item.route)"
35
+ :data-value="item.route"
36
36
  :key="item.route"
37
37
  @select="handleSelect"
38
38
  >
@@ -185,6 +185,13 @@ onMounted(() => {
185
185
  const searchModal = ref(false)
186
186
  const searchWords = ref('')
187
187
  const docs = useArticles()
188
+ const docsMap = computed(() => {
189
+ const map = new Map<string, Theme.PageData.meta>()
190
+ docs.value.forEach((doc) => {
191
+ map.set(withBase(doc.route.replace(/index$/, '')), doc.meta)
192
+ })
193
+ return map
194
+ })
188
195
 
189
196
  const keys = useMagicKeys({
190
197
  passive: false,
@@ -257,19 +264,25 @@ watch(
257
264
  const result = await Promise.all(
258
265
  search.results.map((v: any) => v.data())
259
266
  )
260
- searchResult.value = []
261
- docs.value.forEach((v) => {
262
- const match = result.find((r) =>
263
- r.url.startsWith(withBase(v.route))
264
- )
265
- if (match) {
266
- searchResult.value.push({
267
- ...v,
267
+ searchResult.value = result.map((result) => {
268
+ const { url, excerpt } = result
269
+ const targetRoute = url.replace(/\.html$/, '')
270
+ const meta = docsMap.value.get(targetRoute)
271
+ if (meta) {
272
+ return {
273
+ route: targetRoute,
268
274
  meta: {
269
- ...v.meta,
270
- description: match.excerpt
275
+ ...meta,
276
+ description: excerpt
271
277
  }
272
- })
278
+ }
279
+ }
280
+ return {
281
+ route: url,
282
+ meta: {
283
+ ...result.meta,
284
+ description: excerpt
285
+ }
273
286
  }
274
287
  })
275
288
  })