@sugarat/theme 0.1.35 → 0.1.36-beta.1
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/node.d.ts +9 -3
- package/node.js +125 -31
- package/package.json +4 -4
- package/src/components/BlogHomeBanner.vue +48 -21
- package/src/composables/config/index.ts +6 -1
- package/src/node.ts +58 -17
package/node.d.ts
CHANGED
|
@@ -110,7 +110,8 @@ declare namespace Theme {
|
|
|
110
110
|
interface HomeBlog {
|
|
111
111
|
name?: string;
|
|
112
112
|
motto?: string;
|
|
113
|
-
inspiring?: string;
|
|
113
|
+
inspiring?: string | string[];
|
|
114
|
+
inspiringTimeout?: number;
|
|
114
115
|
pageSize?: number;
|
|
115
116
|
}
|
|
116
117
|
interface ArticleConfig {
|
|
@@ -248,6 +249,10 @@ declare namespace Theme {
|
|
|
248
249
|
blog?: BlogConfig;
|
|
249
250
|
}
|
|
250
251
|
interface HomeConfig {
|
|
252
|
+
/**
|
|
253
|
+
* @deprecated
|
|
254
|
+
* 此方法已经废弃,这个定义将在未来某一刻被移除,请为 inspiring 配置数租来实现相同的效果
|
|
255
|
+
*/
|
|
251
256
|
handleChangeSlogan?: (oldSlogan: string) => string | Promise<string>;
|
|
252
257
|
}
|
|
253
258
|
}
|
|
@@ -257,6 +262,7 @@ declare function getDefaultTitle(content: string): string;
|
|
|
257
262
|
declare function clearMatterContent(content: string): string;
|
|
258
263
|
declare function getFileBirthTime(url: string): string;
|
|
259
264
|
declare function getGitTimestamp(file: string): Promise<unknown>;
|
|
260
|
-
declare function
|
|
265
|
+
declare function assignMermaid(config: any): void;
|
|
266
|
+
declare function defineConfig(config: UserConfig<Theme.Config>): any;
|
|
261
267
|
|
|
262
|
-
export { clearMatterContent, defineConfig, getDefaultTitle, getFileBirthTime, getGitTimestamp, getThemeConfig };
|
|
268
|
+
export { assignMermaid, clearMatterContent, defineConfig, getDefaultTitle, getFileBirthTime, getGitTimestamp, getThemeConfig };
|
package/node.js
CHANGED
|
@@ -26,6 +26,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
26
26
|
// src/node.ts
|
|
27
27
|
var node_exports = {};
|
|
28
28
|
__export(node_exports, {
|
|
29
|
+
assignMermaid: () => assignMermaid,
|
|
29
30
|
clearMatterContent: () => clearMatterContent,
|
|
30
31
|
defineConfig: () => defineConfig,
|
|
31
32
|
getDefaultTitle: () => getDefaultTitle,
|
|
@@ -114,10 +115,10 @@ var ruleBlockTabs = (state, startLine, endLine, silent) => {
|
|
|
114
115
|
var tabBreakRE = /^\s*::(.+)$/;
|
|
115
116
|
var forbiddenCharsInSlotNames = /[ '"]/;
|
|
116
117
|
var parseTabBreakLine = (line) => {
|
|
117
|
-
const
|
|
118
|
-
if (!
|
|
118
|
+
const m2 = line.match(tabBreakRE);
|
|
119
|
+
if (!m2)
|
|
119
120
|
return null;
|
|
120
|
-
const trimmed =
|
|
121
|
+
const trimmed = m2[1].trim();
|
|
121
122
|
if (forbiddenCharsInSlotNames.test(trimmed)) {
|
|
122
123
|
throw new Error(
|
|
123
124
|
`contains forbidden chars in slot names (space and quotes) (${JSON.stringify(
|
|
@@ -205,27 +206,86 @@ var tabsPlugin = (md) => {
|
|
|
205
206
|
};
|
|
206
207
|
};
|
|
207
208
|
|
|
208
|
-
//
|
|
209
|
-
var
|
|
209
|
+
// ../../node_modules/.pnpm/vitepress-plugin-mermaid@2.0.13_mermaid@10.2.4_vitepress@1.0.0-beta.2/node_modules/vitepress-plugin-mermaid/dist/vitepress-plugin-mermaid.es.mjs
|
|
210
|
+
var m = (e) => {
|
|
211
|
+
const r = e.renderer.rules.fence.bind(e.renderer.rules);
|
|
212
|
+
e.renderer.rules.fence = (a, i, t, s, o) => {
|
|
213
|
+
const n = a[i];
|
|
214
|
+
if (n.info.trim() === "mermaid")
|
|
215
|
+
try {
|
|
216
|
+
return `
|
|
217
|
+
<Suspense>
|
|
218
|
+
<template #default>
|
|
219
|
+
<Mermaid id="mermaid-${i}" graph="${encodeURIComponent(
|
|
220
|
+
n.content
|
|
221
|
+
)}"></Mermaid>
|
|
222
|
+
</template>
|
|
223
|
+
<!-- loading state via #fallback slot -->
|
|
224
|
+
<template #fallback>
|
|
225
|
+
Loading...
|
|
226
|
+
</template>
|
|
227
|
+
</Suspense>`;
|
|
228
|
+
} catch (l) {
|
|
229
|
+
return `<pre>${l}</pre>`;
|
|
230
|
+
}
|
|
231
|
+
return n.info.trim() === "mmd" && (a[i].info = "mermaid"), r(a, i, t, s, o);
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
var d = {
|
|
235
|
+
securityLevel: "loose",
|
|
236
|
+
startOnLoad: false
|
|
237
|
+
};
|
|
238
|
+
function p(e) {
|
|
239
|
+
const r = {
|
|
240
|
+
...d,
|
|
241
|
+
...e
|
|
242
|
+
}, a = "virtual:mermaid-config", i = "\0" + a;
|
|
243
|
+
return {
|
|
244
|
+
name: "vite-plugin-mermaid",
|
|
245
|
+
enforce: "post",
|
|
246
|
+
transform(t, s) {
|
|
247
|
+
if (s.includes("vitepress/dist/client/app/index.js"))
|
|
248
|
+
return t = `
|
|
249
|
+
import Mermaid from 'vitepress-plugin-mermaid/Mermaid.vue';
|
|
250
|
+
` + t, t = t.replace(
|
|
251
|
+
"// install global components",
|
|
252
|
+
`// install global components
|
|
253
|
+
app.component('Mermaid', Mermaid);
|
|
254
|
+
`
|
|
255
|
+
), {
|
|
256
|
+
code: t,
|
|
257
|
+
map: null
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
async resolveId(t) {
|
|
261
|
+
if (t === a)
|
|
262
|
+
return i;
|
|
263
|
+
},
|
|
264
|
+
async load(t) {
|
|
265
|
+
if (t === i)
|
|
266
|
+
return `export default ${JSON.stringify(r)};`;
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
210
270
|
|
|
211
271
|
// src/utils/index.ts
|
|
212
|
-
function formatDate(
|
|
213
|
-
if (!(
|
|
214
|
-
|
|
272
|
+
function formatDate(d2, fmt = "yyyy-MM-dd hh:mm:ss") {
|
|
273
|
+
if (!(d2 instanceof Date)) {
|
|
274
|
+
d2 = new Date(d2);
|
|
215
275
|
}
|
|
216
276
|
const o = {
|
|
217
|
-
"M+":
|
|
218
|
-
"d+":
|
|
219
|
-
"h+":
|
|
220
|
-
"m+":
|
|
221
|
-
"s+":
|
|
222
|
-
"q+": Math.floor((
|
|
223
|
-
S:
|
|
277
|
+
"M+": d2.getMonth() + 1,
|
|
278
|
+
"d+": d2.getDate(),
|
|
279
|
+
"h+": d2.getHours(),
|
|
280
|
+
"m+": d2.getMinutes(),
|
|
281
|
+
"s+": d2.getSeconds(),
|
|
282
|
+
"q+": Math.floor((d2.getMonth() + 3) / 3),
|
|
283
|
+
S: d2.getMilliseconds()
|
|
224
284
|
};
|
|
225
285
|
if (/(y+)/.test(fmt)) {
|
|
226
286
|
fmt = fmt.replace(
|
|
227
287
|
RegExp.$1,
|
|
228
|
-
`${
|
|
288
|
+
`${d2.getFullYear()}`.substr(4 - RegExp.$1.length)
|
|
229
289
|
);
|
|
230
290
|
}
|
|
231
291
|
for (const k in o) {
|
|
@@ -346,23 +406,22 @@ function getThemeConfig(cfg) {
|
|
|
346
406
|
]
|
|
347
407
|
};
|
|
348
408
|
}
|
|
409
|
+
const markdownPlugin = [];
|
|
349
410
|
if (cfg?.tabs) {
|
|
350
|
-
|
|
351
|
-
config(md) {
|
|
352
|
-
tabsPlugin(md);
|
|
353
|
-
}
|
|
354
|
-
};
|
|
411
|
+
markdownPlugin.push(tabsPlugin);
|
|
355
412
|
}
|
|
356
413
|
if (cfg) {
|
|
357
414
|
cfg.mermaid = cfg?.mermaid ?? false;
|
|
358
415
|
}
|
|
359
416
|
if (cfg?.mermaid !== false) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
417
|
+
markdownPlugin.push(m);
|
|
418
|
+
}
|
|
419
|
+
if (markdownPlugin.length) {
|
|
420
|
+
extraConfig.markdown = {
|
|
421
|
+
config(...rest) {
|
|
422
|
+
markdownPlugin.forEach((plugin) => {
|
|
423
|
+
plugin?.(...rest);
|
|
424
|
+
});
|
|
366
425
|
}
|
|
367
426
|
};
|
|
368
427
|
}
|
|
@@ -425,8 +484,8 @@ function getGitTimestamp(file) {
|
|
|
425
484
|
return new Promise((resolve, reject) => {
|
|
426
485
|
const child = (0, import_child_process.spawn)("git", ["log", "-1", '--pretty="%ci"', file]);
|
|
427
486
|
let output = "";
|
|
428
|
-
child.stdout.on("data", (
|
|
429
|
-
output += String(
|
|
487
|
+
child.stdout.on("data", (d2) => {
|
|
488
|
+
output += String(d2);
|
|
430
489
|
});
|
|
431
490
|
child.on("close", () => {
|
|
432
491
|
resolve(+new Date(output));
|
|
@@ -437,6 +496,39 @@ function getGitTimestamp(file) {
|
|
|
437
496
|
function getTextSummary(text, count = 100) {
|
|
438
497
|
return clearMatterContent(text).match(/^# ([\s\S]+)/m)?.[1]?.replace(/#/g, "")?.replace(/!\[.*?\]\(.*?\)/g, "")?.replace(/\[(.*?)\]\(.*?\)/g, "$1")?.replace(/\*\*(.*?)\*\*/g, "$1")?.split("\n")?.filter((v) => !!v)?.slice(1)?.join("\n")?.replace(/>(.*)/, "")?.slice(0, count);
|
|
439
498
|
}
|
|
499
|
+
function assignMermaid(config) {
|
|
500
|
+
if (!config.mermaid)
|
|
501
|
+
return;
|
|
502
|
+
if (!config.vite)
|
|
503
|
+
config.vite = {};
|
|
504
|
+
if (!config.vite.plugins)
|
|
505
|
+
config.vite.plugins = [];
|
|
506
|
+
config.vite.plugins.push(p(config.mermaid));
|
|
507
|
+
if (!config.vite.optimizeDeps)
|
|
508
|
+
config.vite.optimizeDeps = {};
|
|
509
|
+
config.vite.optimizeDeps = {
|
|
510
|
+
...config.vite.optimizeDeps,
|
|
511
|
+
include: [
|
|
512
|
+
"@braintree/sanitize-url",
|
|
513
|
+
"dayjs",
|
|
514
|
+
"debug",
|
|
515
|
+
"cytoscape-cose-bilkent",
|
|
516
|
+
"cytoscape"
|
|
517
|
+
]
|
|
518
|
+
};
|
|
519
|
+
if (!config.vite.resolve)
|
|
520
|
+
config.vite.resolve = {};
|
|
521
|
+
if (!config.vite.resolve.alias)
|
|
522
|
+
config.vite.resolve.alias = {};
|
|
523
|
+
config.vite.resolve.alias = {
|
|
524
|
+
...config.vite.resolve.alias,
|
|
525
|
+
"dayjs/plugin/advancedFormat.js": "dayjs/esm/plugin/advancedFormat",
|
|
526
|
+
"dayjs/plugin/customParseFormat.js": "dayjs/esm/plugin/customParseFormat",
|
|
527
|
+
"dayjs/plugin/isoWeek.js": "dayjs/esm/plugin/isoWeek",
|
|
528
|
+
"cytoscape/dist/cytoscape.umd.js": "cytoscape/dist/cytoscape.esm.js",
|
|
529
|
+
mermaid: "mermaid/dist/mermaid.esm.mjs"
|
|
530
|
+
};
|
|
531
|
+
}
|
|
440
532
|
function defineConfig(config) {
|
|
441
533
|
if (config.themeConfig?.themeConfig) {
|
|
442
534
|
config.extends = checkKeys.reduce((pre, key) => {
|
|
@@ -450,10 +542,11 @@ function defineConfig(config) {
|
|
|
450
542
|
}, 1200);
|
|
451
543
|
}
|
|
452
544
|
const extendThemeConfig = config.extends?.themeConfig?.blog;
|
|
453
|
-
const resultConfig = extendThemeConfig.mermaid === false ? config :
|
|
545
|
+
const resultConfig = extendThemeConfig.mermaid === false ? config : {
|
|
454
546
|
...config,
|
|
455
547
|
mermaid: extendThemeConfig.mermaid === true ? {} : extendThemeConfig.mermaid
|
|
456
|
-
}
|
|
548
|
+
};
|
|
549
|
+
assignMermaid(resultConfig);
|
|
457
550
|
if (!resultConfig.markdown)
|
|
458
551
|
resultConfig.markdown = {};
|
|
459
552
|
if (config.extends?.markdown?.config) {
|
|
@@ -468,6 +561,7 @@ function defineConfig(config) {
|
|
|
468
561
|
}
|
|
469
562
|
// Annotate the CommonJS export names for ESM import in node:
|
|
470
563
|
0 && (module.exports = {
|
|
564
|
+
assignMermaid,
|
|
471
565
|
clearMatterContent,
|
|
472
566
|
defineConfig,
|
|
473
567
|
getDefaultTitle,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sugarat/theme",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36-beta.1",
|
|
4
4
|
"description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@mdit-vue/shared": "^0.12.0",
|
|
37
|
-
"@mermaid-js/mermaid-mindmap": "^9.3.0",
|
|
38
37
|
"@vue/shared": "^3.2.45",
|
|
39
38
|
"@vueuse/core": "^9.6.0",
|
|
40
39
|
"fast-glob": "^3.2.12",
|
|
41
40
|
"gray-matter": "^4.0.3",
|
|
42
41
|
"highlight.js": "^11.7.0",
|
|
43
|
-
"mermaid": "^10.2.4",
|
|
44
|
-
"vitepress-plugin-mermaid": "^2.0.13",
|
|
45
42
|
"vue-command-palette": "^0.1.4"
|
|
46
43
|
},
|
|
47
44
|
"devDependencies": {
|
|
45
|
+
"@mermaid-js/mermaid-mindmap": "^9.3.0",
|
|
46
|
+
"mermaid": "^10.2.4",
|
|
47
|
+
"vitepress-plugin-mermaid": "^2.0.13",
|
|
48
48
|
"@element-plus/icons-vue": "^2.1.0",
|
|
49
49
|
"element-plus": "^2.3.4",
|
|
50
50
|
"sass": "^1.56.1",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
</template>
|
|
12
12
|
<script setup lang="ts">
|
|
13
|
-
import { computed, ref } from 'vue'
|
|
13
|
+
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
14
14
|
import { useData } from 'vitepress'
|
|
15
|
-
import {
|
|
15
|
+
import { useBlogConfig } from '../composables/config/blog'
|
|
16
16
|
|
|
17
17
|
const { site, frontmatter } = useData()
|
|
18
18
|
const { home } = useBlogConfig()
|
|
@@ -21,34 +21,61 @@ const name = computed(
|
|
|
21
21
|
() => (frontmatter.value.blog?.name ?? site.value.title) || home?.name || ''
|
|
22
22
|
)
|
|
23
23
|
const motto = computed(() => frontmatter.value.blog?.motto || home?.motto || '')
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
|
|
25
|
+
const inspiring = ref('')
|
|
26
|
+
const inspiringList = computed<string[]>(() => {
|
|
27
|
+
return [
|
|
28
|
+
...new Set(
|
|
29
|
+
[frontmatter.value.blog?.inspiring, home?.inspiring]
|
|
30
|
+
.flat()
|
|
31
|
+
.filter((v) => !!v)
|
|
32
|
+
)
|
|
33
|
+
]
|
|
34
|
+
})
|
|
35
|
+
const inspiringIndex = ref<number>(-1)
|
|
36
|
+
const inspiringTimeout = computed<number>(
|
|
37
|
+
() => frontmatter.value.blog?.inspiringTimeout || home?.inspiringTimeout || 0
|
|
26
38
|
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
|
|
40
|
+
watch(inspiringTimeout, () => {
|
|
41
|
+
startTimer()
|
|
42
|
+
})
|
|
43
|
+
const timer = ref<any>(0)
|
|
44
|
+
const startTimer = () => {
|
|
45
|
+
if (timer.value) {
|
|
46
|
+
clearTimeout(timer.value)
|
|
47
|
+
}
|
|
48
|
+
if (inspiringTimeout.value > 0) {
|
|
49
|
+
timer.value = setTimeout(() => {
|
|
50
|
+
changeSlogan()
|
|
51
|
+
}, inspiringTimeout.value)
|
|
33
52
|
}
|
|
53
|
+
}
|
|
54
|
+
onMounted(() => {
|
|
55
|
+
changeSlogan()
|
|
34
56
|
})
|
|
35
57
|
|
|
36
|
-
|
|
58
|
+
onUnmounted(() => {
|
|
59
|
+
if (timer.value) {
|
|
60
|
+
clearTimeout(timer.value)
|
|
61
|
+
}
|
|
62
|
+
})
|
|
37
63
|
|
|
38
64
|
const changeSlogan = async () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
65
|
+
// 顺手启动定时器
|
|
66
|
+
startTimer()
|
|
67
|
+
|
|
68
|
+
if (inspiringList.value.length < 1) return
|
|
69
|
+
|
|
70
|
+
inspiringIndex.value = (inspiringIndex.value + 1) % inspiringList.value.length
|
|
71
|
+
const newValue = inspiringList.value[inspiringIndex.value]
|
|
72
|
+
if (newValue === inspiring.value) return
|
|
46
73
|
|
|
47
74
|
// 重新渲染数据,同时触发动画
|
|
48
75
|
inspiring.value = ''
|
|
49
|
-
setTimeout(
|
|
50
|
-
inspiring.value =
|
|
51
|
-
})
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
inspiring.value = newValue
|
|
78
|
+
}, 100)
|
|
52
79
|
}
|
|
53
80
|
</script>
|
|
54
81
|
<style lang="scss" scoped>
|
|
@@ -116,7 +116,8 @@ export namespace Theme {
|
|
|
116
116
|
export interface HomeBlog {
|
|
117
117
|
name?: string
|
|
118
118
|
motto?: string
|
|
119
|
-
inspiring?: string
|
|
119
|
+
inspiring?: string | string[]
|
|
120
|
+
inspiringTimeout?: number
|
|
120
121
|
pageSize?: number
|
|
121
122
|
}
|
|
122
123
|
|
|
@@ -269,6 +270,10 @@ export namespace Theme {
|
|
|
269
270
|
blog?: BlogConfig
|
|
270
271
|
}
|
|
271
272
|
export interface HomeConfig {
|
|
273
|
+
/**
|
|
274
|
+
* @deprecated
|
|
275
|
+
* 此方法已经废弃,这个定义将在未来某一刻被移除,请为 inspiring 配置数租来实现相同的效果
|
|
276
|
+
*/
|
|
272
277
|
handleChangeSlogan?: (oldSlogan: string) => string | Promise<string>
|
|
273
278
|
}
|
|
274
279
|
}
|
package/src/node.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { execSync, spawn, spawnSync } from 'child_process'
|
|
|
6
6
|
import path from 'path'
|
|
7
7
|
import type { SiteConfig, UserConfig } from 'vitepress'
|
|
8
8
|
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
|
|
9
|
-
import {
|
|
9
|
+
import { MermaidMarkdown, MermaidPlugin } from 'vitepress-plugin-mermaid'
|
|
10
10
|
import { formatDate } from './utils/index'
|
|
11
11
|
import type { Theme } from './composables/config/index'
|
|
12
12
|
|
|
@@ -170,25 +170,35 @@ export function getThemeConfig(cfg?: Partial<Theme.BlogConfig>) {
|
|
|
170
170
|
]
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
+
const markdownPlugin: any[] = []
|
|
174
|
+
// tabs支持
|
|
173
175
|
if (cfg?.tabs) {
|
|
174
|
-
|
|
175
|
-
config(md: any) {
|
|
176
|
-
tabsMarkdownPlugin(md)
|
|
177
|
-
}
|
|
178
|
-
}
|
|
176
|
+
markdownPlugin.push(tabsMarkdownPlugin)
|
|
179
177
|
}
|
|
178
|
+
|
|
179
|
+
// 流程图支持
|
|
180
180
|
if (cfg) {
|
|
181
181
|
cfg.mermaid = cfg?.mermaid ?? false
|
|
182
182
|
}
|
|
183
|
-
|
|
184
|
-
// 流程图支持
|
|
185
183
|
if (cfg?.mermaid !== false) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
markdownPlugin.push(MermaidMarkdown)
|
|
185
|
+
// extraConfig.vite = {
|
|
186
|
+
// ...extraConfig.vite,
|
|
187
|
+
// resolve: {
|
|
188
|
+
// alias: {
|
|
189
|
+
// mermaid: 'mermaid/dist/mermaid.esm.mjs'
|
|
190
|
+
// }
|
|
191
|
+
// }
|
|
192
|
+
// }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// 注册markdown插件
|
|
196
|
+
if (markdownPlugin.length) {
|
|
197
|
+
extraConfig.markdown = {
|
|
198
|
+
config(...rest: any[]) {
|
|
199
|
+
markdownPlugin.forEach((plugin) => {
|
|
200
|
+
plugin?.(...rest)
|
|
201
|
+
})
|
|
192
202
|
}
|
|
193
203
|
}
|
|
194
204
|
}
|
|
@@ -306,7 +316,37 @@ function getTextSummary(text: string, count = 100) {
|
|
|
306
316
|
)
|
|
307
317
|
}
|
|
308
318
|
|
|
309
|
-
export function
|
|
319
|
+
export function assignMermaid(config: any) {
|
|
320
|
+
if (!config.mermaid) return
|
|
321
|
+
|
|
322
|
+
if (!config.vite) config.vite = {}
|
|
323
|
+
if (!config.vite.plugins) config.vite.plugins = []
|
|
324
|
+
config.vite.plugins.push(MermaidPlugin(config.mermaid))
|
|
325
|
+
if (!config.vite.optimizeDeps) config.vite.optimizeDeps = {}
|
|
326
|
+
config.vite.optimizeDeps = {
|
|
327
|
+
...config.vite.optimizeDeps,
|
|
328
|
+
include: [
|
|
329
|
+
'@braintree/sanitize-url',
|
|
330
|
+
'dayjs',
|
|
331
|
+
'debug',
|
|
332
|
+
'cytoscape-cose-bilkent',
|
|
333
|
+
'cytoscape'
|
|
334
|
+
]
|
|
335
|
+
}
|
|
336
|
+
if (!config.vite.resolve) config.vite.resolve = {}
|
|
337
|
+
if (!config.vite.resolve.alias) config.vite.resolve.alias = {}
|
|
338
|
+
|
|
339
|
+
config.vite.resolve.alias = {
|
|
340
|
+
...config.vite.resolve.alias,
|
|
341
|
+
'dayjs/plugin/advancedFormat.js': 'dayjs/esm/plugin/advancedFormat',
|
|
342
|
+
'dayjs/plugin/customParseFormat.js': 'dayjs/esm/plugin/customParseFormat',
|
|
343
|
+
'dayjs/plugin/isoWeek.js': 'dayjs/esm/plugin/isoWeek',
|
|
344
|
+
'cytoscape/dist/cytoscape.umd.js': 'cytoscape/dist/cytoscape.esm.js',
|
|
345
|
+
mermaid: 'mermaid/dist/mermaid.esm.mjs'
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export function defineConfig(config: UserConfig<Theme.Config>): any {
|
|
310
350
|
// 兼容低版本主题配置
|
|
311
351
|
// @ts-ignore
|
|
312
352
|
if (config.themeConfig?.themeConfig) {
|
|
@@ -332,11 +372,12 @@ export function defineConfig(config: UserConfig<Theme.Config>) {
|
|
|
332
372
|
const resultConfig =
|
|
333
373
|
extendThemeConfig.mermaid === false
|
|
334
374
|
? config
|
|
335
|
-
:
|
|
375
|
+
: {
|
|
336
376
|
...config,
|
|
337
377
|
mermaid:
|
|
338
378
|
extendThemeConfig.mermaid === true ? {} : extendThemeConfig.mermaid
|
|
339
|
-
}
|
|
379
|
+
}
|
|
380
|
+
assignMermaid(resultConfig)
|
|
340
381
|
|
|
341
382
|
// 处理markdown插件
|
|
342
383
|
if (!resultConfig.markdown) resultConfig.markdown = {}
|