@ruan-cat/vitepress-preset-config 1.3.0 → 2.0.0
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/dist/config.d.mts +42 -2
- package/dist/config.mjs +74 -42
- package/dist/theme.d.mts +0 -2
- package/dist/theme.mjs +4 -1
- package/package.json +10 -10
- package/src/config/index.ts +4 -0
- package/src/config/plugins.ts +53 -0
- package/src/config/teek.ts +59 -0
- package/src/config.mts +38 -86
- package/src/index.ts +6 -0
- package/src/theme.ts +7 -1
- package/src/types.ts +49 -0
- package/src/.vitepress/config.mts +0 -35
- package/src/.vitepress/theme/index.ts +0 -15
- package/src/.vitepress/theme/style.css +0 -130
- package/src/bug-to-fix/code-line-number-bug/code/001/index.ts +0 -9
- package/src/bug-to-fix/code-line-number-bug/code/001/raw-code-twoslash.txt +0 -17
- package/src/bug-to-fix/code-line-number-bug/code/001/raw-code.txt +0 -11
- package/src/bug-to-fix/code-line-number-bug/code/002/index.ts +0 -56
- package/src/bug-to-fix/code-line-number-bug/code/002/raw-code-twoslash.txt +0 -89
- package/src/bug-to-fix/code-line-number-bug/code/002/raw-code.txt +0 -70
- package/src/bug-to-fix/code-line-number-bug/try-to-fix-lineNumberPlugin.ts +0 -49
package/dist/config.d.mts
CHANGED
|
@@ -2,8 +2,48 @@ import * as vitepress_sidebar_types from 'vitepress-sidebar/types';
|
|
|
2
2
|
import { UserConfig, DefaultTheme } from 'vitepress';
|
|
3
3
|
export { defineConfig } from 'vitepress';
|
|
4
4
|
import { generateSidebar } from 'vitepress-sidebar';
|
|
5
|
+
import llmstxt from 'vitepress-plugin-llms';
|
|
6
|
+
import { GitChangelog, GitChangelogMarkdownSectionOptions } from '@nolebase/vitepress-plugin-git-changelog/vite';
|
|
7
|
+
import { defineTeekConfig } from 'vitepress-theme-teek/config';
|
|
5
8
|
export { addChangelog2doc, copyReadmeMd } from '@ruan-cat/utils/node-esm';
|
|
6
|
-
|
|
9
|
+
|
|
10
|
+
type LlmstxtSettings = NonNullable<Parameters<typeof llmstxt>[0]>;
|
|
11
|
+
type GitChangelogOptions = NonNullable<Parameters<typeof GitChangelog>[0]>;
|
|
12
|
+
type TeekConfigOptions = NonNullable<Parameters<typeof defineTeekConfig>[0]>;
|
|
13
|
+
/**
|
|
14
|
+
* 额外的配置
|
|
15
|
+
* @description
|
|
16
|
+
* 目前主要用于精细化配置 vitepress 的插件
|
|
17
|
+
*/
|
|
18
|
+
interface ExtraConfig {
|
|
19
|
+
/**
|
|
20
|
+
* 即 vite 的 plugins
|
|
21
|
+
* @description
|
|
22
|
+
* vitepress 配置的一系列插件
|
|
23
|
+
*/
|
|
24
|
+
plugins?: {
|
|
25
|
+
/**
|
|
26
|
+
* @description 用于配置 vitepress-plugin-llms 插件
|
|
27
|
+
* @see https://github.com/okineadev/vitepress-plugin-llms
|
|
28
|
+
*/
|
|
29
|
+
llmstxt?: LlmstxtSettings | false;
|
|
30
|
+
/**
|
|
31
|
+
* @description 用于配置 @nolebase/vitepress-plugin-git-changelog 插件
|
|
32
|
+
* @see
|
|
33
|
+
*/
|
|
34
|
+
gitChangelog?: GitChangelogOptions | false;
|
|
35
|
+
/**
|
|
36
|
+
* @description 用于配置 @nolebase/vitepress-plugin-git-changelog-markdown-section 插件
|
|
37
|
+
* @see
|
|
38
|
+
*/
|
|
39
|
+
gitChangelogMarkdownSection?: GitChangelogMarkdownSectionOptions | false;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Teek 主题配置
|
|
43
|
+
* @see https://vp.teek.top/reference/config.html
|
|
44
|
+
*/
|
|
45
|
+
teekConfig?: TeekConfigOptions;
|
|
46
|
+
}
|
|
7
47
|
|
|
8
48
|
type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
|
|
9
49
|
/**
|
|
@@ -12,6 +52,6 @@ type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
|
|
|
12
52
|
*/
|
|
13
53
|
declare function setGenerateSidebar(options?: VitePressSidebarOptions): vitepress_sidebar_types.Sidebar;
|
|
14
54
|
/** 设置vitepress主配置 */
|
|
15
|
-
declare function setUserConfig(config?: UserConfig<DefaultTheme.Config
|
|
55
|
+
declare function setUserConfig(config?: UserConfig<DefaultTheme.Config>, extraConfig?: ExtraConfig): UserConfig<DefaultTheme.Config>;
|
|
16
56
|
|
|
17
57
|
export { setGenerateSidebar, setUserConfig };
|
package/dist/config.mjs
CHANGED
|
@@ -1,16 +1,50 @@
|
|
|
1
1
|
// src/config.mts
|
|
2
2
|
import { defineConfig } from "vitepress";
|
|
3
3
|
import { generateSidebar } from "vitepress-sidebar";
|
|
4
|
-
import { GitChangelog, GitChangelogMarkdownSection } from "@nolebase/vitepress-plugin-git-changelog/vite";
|
|
5
4
|
import { vitepressDemoPlugin } from "vitepress-demo-plugin";
|
|
6
|
-
import { merge, isUndefined, cloneDeep } from "lodash-es";
|
|
5
|
+
import { merge as merge2, isUndefined, cloneDeep as cloneDeep2 } from "lodash-es";
|
|
7
6
|
import consola from "consola";
|
|
8
7
|
import { addChangelog2doc, hasChangelogMd, copyReadmeMd } from "@ruan-cat/utils/node-esm";
|
|
9
8
|
import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
|
|
10
|
+
// src/config/plugins.ts
|
|
11
|
+
import vitepressPluginLlmstxt from "vitepress-plugin-llms";
|
|
12
|
+
import { GitChangelog, GitChangelogMarkdownSection } from "@nolebase/vitepress-plugin-git-changelog/vite";
|
|
13
|
+
function isFalse(value) {
|
|
14
|
+
return value === false;
|
|
15
|
+
}
|
|
16
|
+
var defaultGitChangelogOptions = {
|
|
17
|
+
// 填写在此处填写您的仓库链接
|
|
18
|
+
repoURL: () => "https://github.com/ruan-cat/monorepo",
|
|
19
|
+
// 最大日志深度为10, 避免获取过多无意义的历史日志
|
|
20
|
+
maxGitLogCount: 10
|
|
21
|
+
};
|
|
22
|
+
function getPlugins(extraConfig) {
|
|
23
|
+
const plugins = [];
|
|
24
|
+
const {
|
|
25
|
+
llmstxt,
|
|
26
|
+
gitChangelog = defaultGitChangelogOptions,
|
|
27
|
+
gitChangelogMarkdownSection
|
|
28
|
+
} = (extraConfig == null ? void 0 : extraConfig.plugins) || {};
|
|
29
|
+
if (!isFalse(llmstxt)) {
|
|
30
|
+
plugins.push(vitepressPluginLlmstxt(llmstxt));
|
|
31
|
+
}
|
|
32
|
+
if (!isFalse(gitChangelog)) {
|
|
33
|
+
plugins.push(GitChangelog(gitChangelog));
|
|
34
|
+
}
|
|
35
|
+
if (!isFalse(gitChangelogMarkdownSection)) {
|
|
36
|
+
plugins.push(GitChangelogMarkdownSection(gitChangelogMarkdownSection));
|
|
37
|
+
}
|
|
38
|
+
return plugins;
|
|
39
|
+
}
|
|
40
|
+
function handlePlugins(userConfig, extraConfig) {
|
|
41
|
+
userConfig.vite.plugins = getPlugins(extraConfig);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/config/teek.ts
|
|
12
45
|
import { defineTeekConfig } from "vitepress-theme-teek/config";
|
|
13
|
-
|
|
46
|
+
import { merge, cloneDeep } from "lodash-es";
|
|
47
|
+
var defaultTeekConfig = {
|
|
14
48
|
/** @see https://vp.teek.top/reference/config/global-config.html#sidebartrigger */
|
|
15
49
|
sidebarTrigger: true,
|
|
16
50
|
/**
|
|
@@ -48,7 +82,15 @@ var teekConfig = defineTeekConfig({
|
|
|
48
82
|
hash: false
|
|
49
83
|
// 是否包含哈希值
|
|
50
84
|
}
|
|
51
|
-
}
|
|
85
|
+
};
|
|
86
|
+
function handleTeekConfig(userConfig, extraConfig) {
|
|
87
|
+
const { teekConfig = defaultTeekConfig } = extraConfig ?? {};
|
|
88
|
+
userConfig.extends = defineTeekConfig(merge({}, cloneDeep(defaultTeekConfig), teekConfig));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/config.mts
|
|
92
|
+
import { MermaidPlugin } from "@leelaa/vitepress-plugin-extended";
|
|
93
|
+
import { defineTeekConfig as defineTeekConfig2 } from "vitepress-theme-teek/config";
|
|
52
94
|
var defaultSidebarOptions = {
|
|
53
95
|
// documentRootPath: "src",
|
|
54
96
|
// 侧边栏需要折叠
|
|
@@ -75,13 +117,17 @@ var defaultSidebarOptions = {
|
|
|
75
117
|
debugPrint: false
|
|
76
118
|
};
|
|
77
119
|
function getMergeSidebarOptions(options) {
|
|
78
|
-
return
|
|
120
|
+
return merge2({}, cloneDeep2(defaultSidebarOptions), isUndefined(options) ? {} : options);
|
|
79
121
|
}
|
|
80
122
|
function setGenerateSidebar(options) {
|
|
81
123
|
return generateSidebar(getMergeSidebarOptions(options));
|
|
82
124
|
}
|
|
83
125
|
var defaultUserConfig = {
|
|
84
|
-
|
|
126
|
+
/**
|
|
127
|
+
* 使用默认的 Teek 主题配置
|
|
128
|
+
* 后续会有函数重新设置 Teek 主题配置,并覆盖默认配置
|
|
129
|
+
*/
|
|
130
|
+
extends: defineTeekConfig2(defaultTeekConfig),
|
|
85
131
|
title: "\u8BF7\u586B\u5199\u6709\u610F\u4E49\u7684\u6807\u9898",
|
|
86
132
|
description: "\u8BF7\u586B\u5199\u6709\u610F\u4E49\u7684\u63CF\u8FF0",
|
|
87
133
|
lang: "zh",
|
|
@@ -89,9 +135,7 @@ var defaultUserConfig = {
|
|
|
89
135
|
// srcDir: "./src",
|
|
90
136
|
themeConfig: {
|
|
91
137
|
i18nRouting: true,
|
|
92
|
-
search: {
|
|
93
|
-
provider: "local"
|
|
94
|
-
},
|
|
138
|
+
search: { provider: "local" },
|
|
95
139
|
// https://vitepress.dev/reference/default-theme-config
|
|
96
140
|
nav: [{ text: "\u9996\u9875", link: "/" }],
|
|
97
141
|
outline: {
|
|
@@ -100,35 +144,17 @@ var defaultUserConfig = {
|
|
|
100
144
|
},
|
|
101
145
|
// 自动化侧边栏
|
|
102
146
|
sidebar: setGenerateSidebar(),
|
|
103
|
-
socialLinks: [
|
|
104
|
-
{
|
|
105
|
-
icon: "github",
|
|
106
|
-
link: "https://github.com/ruan-cat"
|
|
107
|
-
}
|
|
108
|
-
]
|
|
147
|
+
socialLinks: [{ icon: "github", link: "https://github.com/ruan-cat" }]
|
|
109
148
|
},
|
|
110
149
|
vite: {
|
|
111
|
-
server: {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// @ts-ignore
|
|
120
|
-
GitChangelog({
|
|
121
|
-
// 填写在此处填写您的仓库链接
|
|
122
|
-
repoURL: () => "https://github.com/ruan-cat/monorepo",
|
|
123
|
-
// 最大日志深度为10, 避免获取过多无意义的历史日志
|
|
124
|
-
maxGitLogCount: 10
|
|
125
|
-
}),
|
|
126
|
-
// @ts-ignore
|
|
127
|
-
GitChangelogMarkdownSection()
|
|
128
|
-
],
|
|
129
|
-
optimizeDeps: {
|
|
130
|
-
exclude: ["vitepress", "@nolebase/ui"]
|
|
131
|
-
},
|
|
150
|
+
server: { open: true, port: 8080 },
|
|
151
|
+
/**
|
|
152
|
+
* 插件
|
|
153
|
+
* @description
|
|
154
|
+
* 这里留空 插件在 config/plugins.ts 中配置
|
|
155
|
+
*/
|
|
156
|
+
plugins: [],
|
|
157
|
+
optimizeDeps: { exclude: ["vitepress", "@nolebase/ui"] },
|
|
132
158
|
ssr: {
|
|
133
159
|
noExternal: [
|
|
134
160
|
// 如果还有别的依赖需要添加的话,并排填写和配置到这里即可
|
|
@@ -139,6 +165,7 @@ var defaultUserConfig = {
|
|
|
139
165
|
markdown: {
|
|
140
166
|
config(md) {
|
|
141
167
|
md.use(vitepressDemoPlugin);
|
|
168
|
+
MermaidPlugin(md);
|
|
142
169
|
},
|
|
143
170
|
codeTransformers: [
|
|
144
171
|
// @ts-ignore FIXME: 这里出现奇怪的类型报错 屏蔽了
|
|
@@ -149,6 +176,10 @@ var defaultUserConfig = {
|
|
|
149
176
|
* FIXME: 在开启 twoslash 后 ,行号显示是不正确的。 这个故障是vitepress的bug,暂时没有好的方案来解决。
|
|
150
177
|
*/
|
|
151
178
|
lineNumbers: true,
|
|
179
|
+
/** @see https://vitepress-ext.leelaa.cn/Mermaid.html#扩展-md-插件 */
|
|
180
|
+
lazyLoading: true,
|
|
181
|
+
breaks: true,
|
|
182
|
+
math: true,
|
|
152
183
|
container: {
|
|
153
184
|
tipLabel: "\u63D0\u793A",
|
|
154
185
|
warningLabel: "\u8B66\u544A",
|
|
@@ -171,9 +202,11 @@ function handleChangeLog(userConfig) {
|
|
|
171
202
|
}
|
|
172
203
|
nav.push({ text: "\u66F4\u65B0\u65E5\u5FD7", link: "/CHANGELOG.md" });
|
|
173
204
|
}
|
|
174
|
-
function setUserConfig(config) {
|
|
175
|
-
const resUserConfig =
|
|
205
|
+
function setUserConfig(config, extraConfig) {
|
|
206
|
+
const resUserConfig = merge2({}, cloneDeep2(defaultUserConfig), isUndefined(config) ? {} : config);
|
|
176
207
|
handleChangeLog(resUserConfig);
|
|
208
|
+
handlePlugins(resUserConfig, extraConfig);
|
|
209
|
+
handleTeekConfig(resUserConfig, extraConfig);
|
|
177
210
|
return resUserConfig;
|
|
178
211
|
}
|
|
179
212
|
export {
|
|
@@ -181,6 +214,5 @@ export {
|
|
|
181
214
|
copyReadmeMd,
|
|
182
215
|
defineConfig,
|
|
183
216
|
setGenerateSidebar,
|
|
184
|
-
setUserConfig
|
|
185
|
-
withMermaid
|
|
217
|
+
setUserConfig
|
|
186
218
|
};
|
package/dist/theme.d.mts
CHANGED
|
@@ -22,7 +22,6 @@ declare const defaultTheme: {
|
|
|
22
22
|
extends: vitepress_theme_teek.DefaultThemeType;
|
|
23
23
|
enhanceApp: (options: EnhanceAppContext) => Promise<void>;
|
|
24
24
|
};
|
|
25
|
-
Layout: vue.DefineComponent;
|
|
26
25
|
enhanceApp({ app, router, siteData }: EnhanceAppContext): void;
|
|
27
26
|
};
|
|
28
27
|
/**
|
|
@@ -37,7 +36,6 @@ declare function defineRuancatPresetTheme(params?: DefineRuancatPresetThemeParam
|
|
|
37
36
|
extends: vitepress_theme_teek.DefaultThemeType;
|
|
38
37
|
enhanceApp: (options: EnhanceAppContext) => Promise<void>;
|
|
39
38
|
};
|
|
40
|
-
Layout: vue.DefineComponent;
|
|
41
39
|
};
|
|
42
40
|
|
|
43
41
|
export { type DefineRuancatPresetThemeParams, type EnhanceAppCallBack, defaultTheme, defineRuancatPresetTheme };
|
package/dist/theme.mjs
CHANGED
|
@@ -5,13 +5,16 @@ import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
|
|
|
5
5
|
import "@shikijs/vitepress-twoslash/style.css";
|
|
6
6
|
import Teek from "vitepress-theme-teek";
|
|
7
7
|
import "vitepress-theme-teek/index.css";
|
|
8
|
+
import { Mermaid } from "@leelaa/vitepress-plugin-extended";
|
|
8
9
|
function defaultEnhanceAppPreset({ app, router, siteData }) {
|
|
9
10
|
app.use(NolebaseGitChangelogPlugin);
|
|
10
11
|
app.use(TwoslashFloatingVue);
|
|
12
|
+
app.component("Mermaid", Mermaid);
|
|
11
13
|
}
|
|
12
14
|
var defaultTheme = {
|
|
13
15
|
extends: Teek,
|
|
14
|
-
|
|
16
|
+
// 有疑惑 根据和 teek 作者的沟通 这个配置可以不写
|
|
17
|
+
// Layout: Teek.Layout,
|
|
15
18
|
enhanceApp({ app, router, siteData }) {
|
|
16
19
|
defaultEnhanceAppPreset({ app, router, siteData });
|
|
17
20
|
}
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruan-cat/vitepress-preset-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "用于给大多数的vitepress项目提供一个预设的配置文件。",
|
|
5
5
|
"homepage": "https://vitepress-preset.ruancat6312.top",
|
|
6
6
|
"types": "./src/config.mts",
|
|
7
7
|
"main": "./src/config.mts",
|
|
8
8
|
"dependencies": {
|
|
9
|
+
"@leelaa/vitepress-plugin-extended": "^1.0.7",
|
|
9
10
|
"@nolebase/vitepress-plugin-git-changelog": "^2.18.2",
|
|
10
|
-
"@shikijs/vitepress-twoslash": "^3.
|
|
11
|
+
"@shikijs/vitepress-twoslash": "^3.12.0",
|
|
11
12
|
"consola": "^3.4.2",
|
|
12
13
|
"js-yaml": "^4.1.0",
|
|
13
14
|
"lodash-es": "^4.17.21",
|
|
14
15
|
"markdown-it-async": "^2.2.0",
|
|
15
|
-
"
|
|
16
|
+
"markdown-it-mathjax3": "^4.3.2",
|
|
16
17
|
"vitepress-demo-plugin": "^1.4.7",
|
|
17
18
|
"vitepress-plugin-llms": "^1.7.3",
|
|
18
|
-
"vitepress-plugin-mermaid": "^2.0.17",
|
|
19
19
|
"vitepress-sidebar": "^1.33.0",
|
|
20
|
-
"vitepress-theme-teek": "^1.4.
|
|
21
|
-
"vue": "^3.5.
|
|
20
|
+
"vitepress-theme-teek": "^1.4.6",
|
|
21
|
+
"vue": "^3.5.20",
|
|
22
22
|
"@ruan-cat/utils": "^4.10.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/lodash-es": "^4.17.12",
|
|
26
26
|
"automd": "^0.4.0",
|
|
27
|
-
"element-plus": "^2.
|
|
27
|
+
"element-plus": "^2.11.1",
|
|
28
28
|
"tsup": "^8.5.0",
|
|
29
29
|
"vitepress": "^1.6.4"
|
|
30
30
|
},
|
|
@@ -89,15 +89,15 @@
|
|
|
89
89
|
"!**/.vercel/**",
|
|
90
90
|
"dist",
|
|
91
91
|
"src",
|
|
92
|
-
"!src/
|
|
92
|
+
"!src/docs/**",
|
|
93
93
|
"!src/**/tests",
|
|
94
94
|
"!src/**/*.md",
|
|
95
95
|
"!src/.vitepress/cache",
|
|
96
96
|
"!src/.vitepress/dist"
|
|
97
97
|
],
|
|
98
98
|
"scripts": {
|
|
99
|
-
"docs:dev": "vitepress dev src --port 8080",
|
|
100
|
-
"build:docs": "vitepress build src",
|
|
99
|
+
"docs:dev": "vitepress dev src/docs --port 8080",
|
|
100
|
+
"build:docs": "vitepress build src/docs",
|
|
101
101
|
"build": "tsup",
|
|
102
102
|
"prebuild": "automd"
|
|
103
103
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type DefaultTheme, type UserConfig } from "vitepress";
|
|
2
|
+
import vitepressPluginLlmstxt from "vitepress-plugin-llms";
|
|
3
|
+
import { GitChangelog, GitChangelogMarkdownSection } from "@nolebase/vitepress-plugin-git-changelog/vite";
|
|
4
|
+
|
|
5
|
+
import type { ExtraConfig, GitChangelogOptions } from "../types.ts";
|
|
6
|
+
|
|
7
|
+
function isFalse(value: unknown): value is false {
|
|
8
|
+
return value === false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const defaultGitChangelogOptions: GitChangelogOptions = {
|
|
12
|
+
// 填写在此处填写您的仓库链接
|
|
13
|
+
repoURL: () => "https://github.com/ruan-cat/monorepo",
|
|
14
|
+
// 最大日志深度为10, 避免获取过多无意义的历史日志
|
|
15
|
+
maxGitLogCount: 10,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 根据配置 返回插件列表
|
|
20
|
+
* @description
|
|
21
|
+
* 该函数将根据具体的配置 返回插件列表
|
|
22
|
+
*/
|
|
23
|
+
export function getPlugins(extraConfig?: ExtraConfig) {
|
|
24
|
+
const plugins = [];
|
|
25
|
+
const {
|
|
26
|
+
llmstxt,
|
|
27
|
+
gitChangelog = defaultGitChangelogOptions,
|
|
28
|
+
gitChangelogMarkdownSection,
|
|
29
|
+
} = extraConfig?.plugins || {};
|
|
30
|
+
|
|
31
|
+
if (!isFalse(llmstxt)) {
|
|
32
|
+
plugins.push(vitepressPluginLlmstxt(llmstxt));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!isFalse(gitChangelog)) {
|
|
36
|
+
plugins.push(GitChangelog(gitChangelog));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!isFalse(gitChangelogMarkdownSection)) {
|
|
40
|
+
plugins.push(GitChangelogMarkdownSection(gitChangelogMarkdownSection));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return plugins;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 根据用户的额外配置 设置`文档配置`的 vite 插件
|
|
48
|
+
* @description
|
|
49
|
+
*/
|
|
50
|
+
export function handlePlugins(userConfig: UserConfig<DefaultTheme.Config>, extraConfig?: ExtraConfig) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
userConfig.vite.plugins = getPlugins(extraConfig);
|
|
53
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type DefaultTheme, type UserConfig } from "vitepress";
|
|
2
|
+
import { defineTeekConfig } from "vitepress-theme-teek/config";
|
|
3
|
+
import { merge, cloneDeep } from "lodash-es";
|
|
4
|
+
|
|
5
|
+
import type { TeekConfigOptions, ExtraConfig } from "../types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 默认的 Teek 主题配置
|
|
9
|
+
* @see https://vp.teek.top/reference/config.html
|
|
10
|
+
*/
|
|
11
|
+
export const defaultTeekConfig: TeekConfigOptions = {
|
|
12
|
+
/** @see https://vp.teek.top/reference/config/global-config.html#sidebartrigger */
|
|
13
|
+
sidebarTrigger: true,
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 关闭 Teek 主题的首页风格
|
|
17
|
+
* @see https://vp.teek.top/reference/config/global-config.html#teekhome
|
|
18
|
+
*/
|
|
19
|
+
teekHome: false,
|
|
20
|
+
|
|
21
|
+
vitePlugins: {
|
|
22
|
+
/**
|
|
23
|
+
* 关闭 vitepress-plugin-permalink 插件
|
|
24
|
+
* @see https://vp.teek.top/guide/plugins.html#vitepress-plugin-permalink
|
|
25
|
+
*/
|
|
26
|
+
permalink: false,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 关闭 vitepress-plugin-sidebar-resolve 插件
|
|
30
|
+
* @see https://vp.teek.top/guide/plugins.html#vitepress-plugin-sidebar-resolve
|
|
31
|
+
*/
|
|
32
|
+
sidebar: false,
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 关闭 vitepress-plugin-md-h1 插件
|
|
36
|
+
* @see https://vp.teek.top/guide/plugins.html#vitepress-plugin-md-h1
|
|
37
|
+
*/
|
|
38
|
+
mdH1: false,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/** @see https://vp.teek.top/reference/article-config.html#articleshare */
|
|
42
|
+
articleShare: {
|
|
43
|
+
enabled: true, // 是否开启文章链接分享功能
|
|
44
|
+
text: "分享此页面", // 分享按钮文本
|
|
45
|
+
copiedText: "链接已复制", // 复制成功文本
|
|
46
|
+
query: false, // 是否包含查询参数
|
|
47
|
+
hash: false, // 是否包含哈希值
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 根据用户的额外配置 设置`文档配置`的 teek 主题配置
|
|
53
|
+
* @description
|
|
54
|
+
*/
|
|
55
|
+
export function handleTeekConfig(userConfig: UserConfig<DefaultTheme.Config>, extraConfig?: ExtraConfig) {
|
|
56
|
+
const { teekConfig = defaultTeekConfig } = extraConfig ?? {};
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
userConfig.extends = defineTeekConfig(merge({}, cloneDeep(defaultTeekConfig), teekConfig));
|
|
59
|
+
}
|
package/src/config.mts
CHANGED
|
@@ -7,6 +7,7 @@ import { vitepressDemoPlugin } from "vitepress-demo-plugin";
|
|
|
7
7
|
|
|
8
8
|
import { merge, isUndefined, cloneDeep } from "lodash-es";
|
|
9
9
|
import consola from "consola";
|
|
10
|
+
import type { ExtraConfig } from "./types.ts";
|
|
10
11
|
|
|
11
12
|
import { addChangelog2doc, hasChangelogMd, copyReadmeMd } from "@ruan-cat/utils/node-esm";
|
|
12
13
|
export { addChangelog2doc, copyReadmeMd };
|
|
@@ -15,62 +16,14 @@ import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
|
|
|
15
16
|
|
|
16
17
|
import llmstxt from "vitepress-plugin-llms";
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import { withMermaid } from "vitepress-plugin-mermaid";
|
|
23
|
-
/**
|
|
24
|
-
* 不考虑这种二次包装的写法
|
|
25
|
-
* 本库仅仅是负责二次导出该函数
|
|
26
|
-
* mermaid 需求并不是常用的需求 故设计成让用户自己二次包装使用
|
|
27
|
-
*/
|
|
28
|
-
export { withMermaid };
|
|
19
|
+
import { defaultTeekConfig, handleTeekConfig, handlePlugins } from "./config/index.ts";
|
|
20
|
+
|
|
21
|
+
/** @see https://vitepress-ext.leelaa.cn/Mermaid.html#扩展-md-插件 */
|
|
22
|
+
import { MermaidPlugin } from "@leelaa/vitepress-plugin-extended";
|
|
29
23
|
|
|
30
24
|
// https://vp.teek.top/guide/quickstart.html#teek-引入
|
|
31
25
|
import { defineTeekConfig } from "vitepress-theme-teek/config";
|
|
32
26
|
|
|
33
|
-
/** Teek 主题配置 */
|
|
34
|
-
const teekConfig = defineTeekConfig({
|
|
35
|
-
/** @see https://vp.teek.top/reference/config/global-config.html#sidebartrigger */
|
|
36
|
-
sidebarTrigger: true,
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 关闭 Teek 主题的首页风格
|
|
40
|
-
* @see https://vp.teek.top/reference/config/global-config.html#teekhome
|
|
41
|
-
*/
|
|
42
|
-
teekHome: false,
|
|
43
|
-
|
|
44
|
-
vitePlugins: {
|
|
45
|
-
/**
|
|
46
|
-
* 关闭 vitepress-plugin-permalink 插件
|
|
47
|
-
* @see https://vp.teek.top/guide/plugins.html#vitepress-plugin-permalink
|
|
48
|
-
*/
|
|
49
|
-
permalink: false,
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 关闭 vitepress-plugin-sidebar-resolve 插件
|
|
53
|
-
* @see https://vp.teek.top/guide/plugins.html#vitepress-plugin-sidebar-resolve
|
|
54
|
-
*/
|
|
55
|
-
sidebar: false,
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 关闭 vitepress-plugin-md-h1 插件
|
|
59
|
-
* @see https://vp.teek.top/guide/plugins.html#vitepress-plugin-md-h1
|
|
60
|
-
*/
|
|
61
|
-
mdH1: false,
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
/** @see https://vp.teek.top/reference/article-config.html#articleshare */
|
|
65
|
-
articleShare: {
|
|
66
|
-
enabled: true, // 是否开启文章链接分享功能
|
|
67
|
-
text: "分享此页面", // 分享按钮文本
|
|
68
|
-
copiedText: "链接已复制", // 复制成功文本
|
|
69
|
-
query: false, // 是否包含查询参数
|
|
70
|
-
hash: false, // 是否包含哈希值
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
|
|
74
27
|
type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
|
|
75
28
|
|
|
76
29
|
/** 默认侧边栏配置 */
|
|
@@ -126,7 +79,11 @@ export function setGenerateSidebar(options?: VitePressSidebarOptions) {
|
|
|
126
79
|
|
|
127
80
|
/** 默认用户配置 */
|
|
128
81
|
const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
129
|
-
|
|
82
|
+
/**
|
|
83
|
+
* 使用默认的 Teek 主题配置
|
|
84
|
+
* 后续会有函数重新设置 Teek 主题配置,并覆盖默认配置
|
|
85
|
+
*/
|
|
86
|
+
extends: defineTeekConfig(defaultTeekConfig),
|
|
130
87
|
|
|
131
88
|
title: "请填写有意义的标题",
|
|
132
89
|
description: "请填写有意义的描述",
|
|
@@ -138,9 +95,7 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
138
95
|
themeConfig: {
|
|
139
96
|
i18nRouting: true,
|
|
140
97
|
|
|
141
|
-
search: {
|
|
142
|
-
provider: "local",
|
|
143
|
-
},
|
|
98
|
+
search: { provider: "local" },
|
|
144
99
|
|
|
145
100
|
// https://vitepress.dev/reference/default-theme-config
|
|
146
101
|
nav: [{ text: "首页", link: "/" }],
|
|
@@ -153,40 +108,20 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
153
108
|
// 自动化侧边栏
|
|
154
109
|
sidebar: setGenerateSidebar(),
|
|
155
110
|
|
|
156
|
-
socialLinks: [
|
|
157
|
-
{
|
|
158
|
-
icon: "github",
|
|
159
|
-
link: "https://github.com/ruan-cat",
|
|
160
|
-
},
|
|
161
|
-
],
|
|
111
|
+
socialLinks: [{ icon: "github", link: "https://github.com/ruan-cat" }],
|
|
162
112
|
},
|
|
163
113
|
|
|
164
114
|
vite: {
|
|
165
|
-
server: {
|
|
166
|
-
open: true,
|
|
167
|
-
port: 8080,
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
plugins: [
|
|
171
|
-
/** @see https://github.com/okineadev/vitepress-plugin-llms */
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
llmstxt(),
|
|
174
|
-
|
|
175
|
-
// @ts-ignore
|
|
176
|
-
GitChangelog({
|
|
177
|
-
// 填写在此处填写您的仓库链接
|
|
178
|
-
repoURL: () => "https://github.com/ruan-cat/monorepo",
|
|
179
|
-
// 最大日志深度为10, 避免获取过多无意义的历史日志
|
|
180
|
-
maxGitLogCount: 10,
|
|
181
|
-
}),
|
|
115
|
+
server: { open: true, port: 8080 },
|
|
182
116
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
117
|
+
/**
|
|
118
|
+
* 插件
|
|
119
|
+
* @description
|
|
120
|
+
* 这里留空 插件在 config/plugins.ts 中配置
|
|
121
|
+
*/
|
|
122
|
+
plugins: [],
|
|
186
123
|
|
|
187
|
-
optimizeDeps: {
|
|
188
|
-
exclude: ["vitepress", "@nolebase/ui"],
|
|
189
|
-
},
|
|
124
|
+
optimizeDeps: { exclude: ["vitepress", "@nolebase/ui"] },
|
|
190
125
|
|
|
191
126
|
ssr: {
|
|
192
127
|
noExternal: [
|
|
@@ -199,6 +134,9 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
199
134
|
markdown: {
|
|
200
135
|
config(md) {
|
|
201
136
|
md.use(vitepressDemoPlugin);
|
|
137
|
+
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
MermaidPlugin(md);
|
|
202
140
|
},
|
|
203
141
|
|
|
204
142
|
codeTransformers: [
|
|
@@ -212,6 +150,11 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
212
150
|
*/
|
|
213
151
|
lineNumbers: true,
|
|
214
152
|
|
|
153
|
+
/** @see https://vitepress-ext.leelaa.cn/Mermaid.html#扩展-md-插件 */
|
|
154
|
+
lazyLoading: true,
|
|
155
|
+
breaks: true,
|
|
156
|
+
math: true,
|
|
157
|
+
|
|
215
158
|
container: {
|
|
216
159
|
tipLabel: "提示",
|
|
217
160
|
warningLabel: "警告",
|
|
@@ -247,12 +190,21 @@ function handleChangeLog(userConfig: UserConfig<DefaultTheme.Config>) {
|
|
|
247
190
|
}
|
|
248
191
|
|
|
249
192
|
/** 设置vitepress主配置 */
|
|
250
|
-
export function setUserConfig(
|
|
193
|
+
export function setUserConfig(
|
|
194
|
+
config?: UserConfig<DefaultTheme.Config>,
|
|
195
|
+
extraConfig?: ExtraConfig,
|
|
196
|
+
): UserConfig<DefaultTheme.Config> {
|
|
251
197
|
/** 最终的用户数据 */
|
|
252
198
|
const resUserConfig = merge({}, cloneDeep(defaultUserConfig), isUndefined(config) ? {} : config);
|
|
253
199
|
|
|
254
200
|
// 增加导航栏
|
|
255
201
|
handleChangeLog(resUserConfig);
|
|
256
202
|
|
|
203
|
+
// 设置插件
|
|
204
|
+
handlePlugins(resUserConfig, extraConfig);
|
|
205
|
+
|
|
206
|
+
// 设置 Teek 主题配置
|
|
207
|
+
handleTeekConfig(resUserConfig, extraConfig);
|
|
208
|
+
|
|
257
209
|
return resUserConfig;
|
|
258
210
|
}
|
package/src/index.ts
ADDED
package/src/theme.ts
CHANGED
|
@@ -17,6 +17,10 @@ import "@shikijs/vitepress-twoslash/style.css";
|
|
|
17
17
|
import Teek from "vitepress-theme-teek";
|
|
18
18
|
import "vitepress-theme-teek/index.css";
|
|
19
19
|
|
|
20
|
+
/** @see https://vitepress-ext.leelaa.cn/Mermaid.html#全局引入 */
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
import { Mermaid } from "@leelaa/vitepress-plugin-extended";
|
|
23
|
+
|
|
20
24
|
/**
|
|
21
25
|
* 一个回调函数 用来暴露变量 实现注册
|
|
22
26
|
*/
|
|
@@ -39,6 +43,7 @@ export interface DefineRuancatPresetThemeParams {
|
|
|
39
43
|
function defaultEnhanceAppPreset({ app, router, siteData }: EnhanceAppContext) {
|
|
40
44
|
app.use(NolebaseGitChangelogPlugin);
|
|
41
45
|
app.use(TwoslashFloatingVue);
|
|
46
|
+
app.component("Mermaid", Mermaid);
|
|
42
47
|
/**
|
|
43
48
|
* 放弃全局注册demo展示组件
|
|
44
49
|
* 在生产环境内使用peer对等依赖
|
|
@@ -50,7 +55,8 @@ function defaultEnhanceAppPreset({ app, router, siteData }: EnhanceAppContext) {
|
|
|
50
55
|
/** 默认主题配置 */
|
|
51
56
|
export const defaultTheme = {
|
|
52
57
|
extends: Teek,
|
|
53
|
-
|
|
58
|
+
// 有疑惑 根据和 teek 作者的沟通 这个配置可以不写
|
|
59
|
+
// Layout: Teek.Layout,
|
|
54
60
|
enhanceApp({ app, router, siteData }: EnhanceAppContext) {
|
|
55
61
|
defaultEnhanceAppPreset({ app, router, siteData });
|
|
56
62
|
},
|