@ruan-cat/vitepress-preset-config 0.0.2 → 0.1.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.mjs +18 -13
- package/dist/theme/index.d.mts +3 -3
- package/dist/theme/index.mjs +3 -0
- package/package.json +5 -6
- package/src/.vitepress/config.mts +13 -1
- package/src/.vitepress/theme/index.ts +7 -3
- package/src/config.mts +25 -13
package/dist/config.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { vitepressDemoPlugin } from "vitepress-demo-plugin";
|
|
|
6
6
|
import { merge, isUndefined, cloneDeep } from "lodash-es";
|
|
7
7
|
import consola from "consola";
|
|
8
8
|
import { addChangelog2doc, hasChangelogMd } from "@ruan-cat/utils/node-esm";
|
|
9
|
+
import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
|
|
9
10
|
var defaultSidebarOptions = {
|
|
10
11
|
// documentRootPath: "src",
|
|
11
12
|
// 侧边栏需要折叠
|
|
@@ -37,8 +38,8 @@ function setGenerateSidebar(options) {
|
|
|
37
38
|
return generateSidebar(getMergeSidebarOptions(options));
|
|
38
39
|
}
|
|
39
40
|
var defaultUserConfig = {
|
|
40
|
-
title: "
|
|
41
|
-
description: "\
|
|
41
|
+
title: "\u8BF7\u586B\u5199\u6709\u610F\u4E49\u7684\u6807\u9898",
|
|
42
|
+
description: "\u8BF7\u586B\u5199\u6709\u610F\u4E49\u7684\u63CF\u8FF0",
|
|
42
43
|
lang: "zh",
|
|
43
44
|
// 暂不需要
|
|
44
45
|
// srcDir: "./src",
|
|
@@ -48,12 +49,7 @@ var defaultUserConfig = {
|
|
|
48
49
|
provider: "local"
|
|
49
50
|
},
|
|
50
51
|
// https://vitepress.dev/reference/default-theme-config
|
|
51
|
-
nav: [
|
|
52
|
-
{ text: "\u9996\u9875", link: "/" },
|
|
53
|
-
{ text: "\u66F4\u65B0\u65E5\u5FD7", link: "/CHANGELOG.md" }
|
|
54
|
-
// TODO: 未来项目结束时,在此补充配置
|
|
55
|
-
// { text: "仓库地址", link: "https://github.com/ruan-cat/vercel-monorepo-test/tree/dev/packages/docs-01-star" },
|
|
56
|
-
],
|
|
52
|
+
nav: [{ text: "\u9996\u9875", link: "/" }],
|
|
57
53
|
outline: {
|
|
58
54
|
label: "\u672C\u9875\u76EE\u5F55",
|
|
59
55
|
level: "deep"
|
|
@@ -63,7 +59,7 @@ var defaultUserConfig = {
|
|
|
63
59
|
socialLinks: [
|
|
64
60
|
{
|
|
65
61
|
icon: "github",
|
|
66
|
-
link: "https://github.com/ruan-cat
|
|
62
|
+
link: "https://github.com/ruan-cat"
|
|
67
63
|
}
|
|
68
64
|
]
|
|
69
65
|
},
|
|
@@ -101,6 +97,18 @@ var defaultUserConfig = {
|
|
|
101
97
|
markdown: {
|
|
102
98
|
config(md) {
|
|
103
99
|
md.use(vitepressDemoPlugin);
|
|
100
|
+
},
|
|
101
|
+
codeTransformers: [
|
|
102
|
+
// @ts-ignore FIXME: 这里出现奇怪的类型报错 屏蔽了
|
|
103
|
+
transformerTwoslash()
|
|
104
|
+
],
|
|
105
|
+
// languages: ["js", "jsx", "ts", "tsx"],
|
|
106
|
+
container: {
|
|
107
|
+
tipLabel: "\u63D0\u793A",
|
|
108
|
+
warningLabel: "\u8B66\u544A",
|
|
109
|
+
dangerLabel: "\u5371\u9669",
|
|
110
|
+
infoLabel: "\u4FE1\u606F",
|
|
111
|
+
detailsLabel: "\u8BE6\u60C5"
|
|
104
112
|
}
|
|
105
113
|
}
|
|
106
114
|
};
|
|
@@ -115,10 +123,7 @@ function handleChangeLog(userConfig) {
|
|
|
115
123
|
consola.error(` \u5F53\u524D\u7684\u7528\u6237\u914D\u7F6E\u4E3A\uFF1A `, userConfig);
|
|
116
124
|
throw new Error(` nav \u9ED8\u8BA4\u63D0\u4F9B\u7684\u5BFC\u822A\u680F\u914D\u7F6E\u4E3A\u7A7A\u3002\u4E0D\u7B26\u5408\u9ED8\u8BA4\u914D\u7F6E\uFF0C\u8BF7\u68C0\u67E5\u3002 `);
|
|
117
125
|
}
|
|
118
|
-
nav.push({
|
|
119
|
-
text: "\u53D8\u66F4\u65E5\u5FD7",
|
|
120
|
-
link: "/CHANGELOG.md"
|
|
121
|
-
});
|
|
126
|
+
nav.push({ text: "\u66F4\u65B0\u65E5\u5FD7", link: "/CHANGELOG.md" });
|
|
122
127
|
}
|
|
123
128
|
function setUserConfig(config) {
|
|
124
129
|
const resUserConfig = merge({}, cloneDeep(defaultUserConfig), isUndefined(config) ? {} : config);
|
package/dist/theme/index.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import * as vitepress from 'vitepress';
|
|
2
1
|
import * as vue from 'vue';
|
|
2
|
+
import { EnhanceAppContext } from 'vitepress';
|
|
3
3
|
|
|
4
4
|
declare const theme: {
|
|
5
5
|
extends: {
|
|
6
6
|
Layout: vue.DefineComponent;
|
|
7
|
-
enhanceApp: (ctx:
|
|
7
|
+
enhanceApp: (ctx: EnhanceAppContext) => void;
|
|
8
8
|
};
|
|
9
9
|
Layout: () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
10
10
|
[key: string]: any;
|
|
11
11
|
}>;
|
|
12
|
-
enhanceApp({ app, router, siteData }:
|
|
12
|
+
enhanceApp({ app, router, siteData }: EnhanceAppContext): void;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export { theme as default };
|
package/dist/theme/index.mjs
CHANGED
|
@@ -13,6 +13,8 @@ import { NolebaseHighlightTargetedHeading } from "@nolebase/vitepress-plugin-hig
|
|
|
13
13
|
import "@nolebase/vitepress-plugin-highlight-targeted-heading/client/style.css";
|
|
14
14
|
import { NolebaseGitChangelogPlugin } from "@nolebase/vitepress-plugin-git-changelog/client";
|
|
15
15
|
import "@nolebase/vitepress-plugin-git-changelog/client/style.css";
|
|
16
|
+
import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
|
|
17
|
+
import "@shikijs/vitepress-twoslash/style.css";
|
|
16
18
|
var theme = {
|
|
17
19
|
extends: DefaultTheme,
|
|
18
20
|
Layout: () => {
|
|
@@ -27,6 +29,7 @@ var theme = {
|
|
|
27
29
|
},
|
|
28
30
|
enhanceApp({ app, router, siteData }) {
|
|
29
31
|
app.use(NolebaseGitChangelogPlugin);
|
|
32
|
+
app.use(TwoslashFloatingVue);
|
|
30
33
|
app.provide(InjectionKey, {
|
|
31
34
|
layoutSwitch: {
|
|
32
35
|
defaultMode: LayoutMode["BothWidthAdjustable"],
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruan-cat/vitepress-preset-config",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "用于给大多数的vitepress项目提供一个预设的配置文件。",
|
|
5
|
-
"homepage": "https://
|
|
5
|
+
"homepage": "https://vitepress-preset.ruancat6312.top",
|
|
6
6
|
"types": "./src/config.mts",
|
|
7
7
|
"main": "./src/config.mts",
|
|
8
8
|
"dependencies": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"@nolebase/vitepress-plugin-enhanced-readabilities": "^2.15.1",
|
|
11
11
|
"@nolebase/vitepress-plugin-git-changelog": "^2.15.1",
|
|
12
12
|
"@nolebase/vitepress-plugin-highlight-targeted-heading": "^2.15.1",
|
|
13
|
+
"@shikijs/vitepress-twoslash": "^3.2.1",
|
|
13
14
|
"consola": "^3.4.0",
|
|
14
15
|
"js-yaml": "^4.1.0",
|
|
15
16
|
"lodash-es": "^4.17.21",
|
|
@@ -81,9 +82,7 @@
|
|
|
81
82
|
],
|
|
82
83
|
"scripts": {
|
|
83
84
|
"docs:dev": "vitepress dev src --port 8080",
|
|
84
|
-
"
|
|
85
|
-
"build
|
|
86
|
-
"do-build": "tsup",
|
|
87
|
-
"build": "turbo do-build"
|
|
85
|
+
"build:docs": "vitepress build src",
|
|
86
|
+
"build": "tsup"
|
|
88
87
|
}
|
|
89
88
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// import { setUserConfig, setGenerateSidebar, addChangelog2doc } from "@ruan-cat/vitepress-preset-config/config";
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
import { setUserConfig, setGenerateSidebar, addChangelog2doc } from "../../src/config.mts";
|
|
5
|
+
import { description } from "../../package.json";
|
|
5
6
|
|
|
6
7
|
addChangelog2doc({
|
|
7
8
|
target: "./src",
|
|
@@ -13,7 +14,18 @@ addChangelog2doc({
|
|
|
13
14
|
/**
|
|
14
15
|
* 本文档的渲染配置
|
|
15
16
|
*/
|
|
16
|
-
const thisDocUserConfig = setUserConfig(
|
|
17
|
+
const thisDocUserConfig = setUserConfig({
|
|
18
|
+
title: "vitepress预设配置",
|
|
19
|
+
description,
|
|
20
|
+
themeConfig: {
|
|
21
|
+
socialLinks: [
|
|
22
|
+
{
|
|
23
|
+
icon: "github",
|
|
24
|
+
link: "https://github.com/ruan-cat/vercel-monorepo-test/tree/main/packages/vitepress-preset-config",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
});
|
|
17
29
|
// @ts-ignore
|
|
18
30
|
thisDocUserConfig.themeConfig.sidebar = setGenerateSidebar({
|
|
19
31
|
documentRootPath: "./src",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://vitepress.dev/guide/custom-theme
|
|
2
2
|
import { h } from "vue";
|
|
3
|
-
import type { Theme } from "vitepress";
|
|
3
|
+
import type { Theme, EnhanceAppContext } from "vitepress";
|
|
4
4
|
import DefaultTheme from "vitepress/theme";
|
|
5
5
|
import "./style.css";
|
|
6
6
|
|
|
@@ -23,6 +23,9 @@ import "@nolebase/vitepress-plugin-highlight-targeted-heading/client/style.css";
|
|
|
23
23
|
import { NolebaseGitChangelogPlugin } from "@nolebase/vitepress-plugin-git-changelog/client";
|
|
24
24
|
import "@nolebase/vitepress-plugin-git-changelog/client/style.css";
|
|
25
25
|
|
|
26
|
+
import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
|
|
27
|
+
import "@shikijs/vitepress-twoslash/style.css";
|
|
28
|
+
|
|
26
29
|
const theme = {
|
|
27
30
|
extends: DefaultTheme,
|
|
28
31
|
Layout: () => {
|
|
@@ -38,10 +41,11 @@ const theme = {
|
|
|
38
41
|
"layout-top": () => [h(NolebaseHighlightTargetedHeading)],
|
|
39
42
|
});
|
|
40
43
|
},
|
|
41
|
-
enhanceApp({ app, router, siteData }) {
|
|
42
|
-
// ...
|
|
44
|
+
enhanceApp({ app, router, siteData }: EnhanceAppContext) {
|
|
43
45
|
app.use(NolebaseGitChangelogPlugin);
|
|
44
46
|
|
|
47
|
+
app.use(TwoslashFloatingVue);
|
|
48
|
+
|
|
45
49
|
app.provide(InjectionKey, {
|
|
46
50
|
layoutSwitch: {
|
|
47
51
|
defaultMode: LayoutMode["BothWidthAdjustable"],
|
package/src/config.mts
CHANGED
|
@@ -12,6 +12,8 @@ import consola from "consola";
|
|
|
12
12
|
import { addChangelog2doc, hasChangelogMd } from "@ruan-cat/utils/node-esm";
|
|
13
13
|
export { addChangelog2doc };
|
|
14
14
|
|
|
15
|
+
import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
|
|
16
|
+
|
|
15
17
|
type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
|
|
16
18
|
|
|
17
19
|
/** 默认侧边栏配置 */
|
|
@@ -66,8 +68,8 @@ export function setGenerateSidebar(options?: VitePressSidebarOptions) {
|
|
|
66
68
|
|
|
67
69
|
/** 默认用户配置 */
|
|
68
70
|
const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
69
|
-
title: "
|
|
70
|
-
description: "
|
|
71
|
+
title: "请填写有意义的标题",
|
|
72
|
+
description: "请填写有意义的描述",
|
|
71
73
|
|
|
72
74
|
lang: "zh",
|
|
73
75
|
// 暂不需要
|
|
@@ -81,12 +83,7 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
81
83
|
},
|
|
82
84
|
|
|
83
85
|
// https://vitepress.dev/reference/default-theme-config
|
|
84
|
-
nav: [
|
|
85
|
-
{ text: "首页", link: "/" },
|
|
86
|
-
{ text: "更新日志", link: "/CHANGELOG.md" },
|
|
87
|
-
// TODO: 未来项目结束时,在此补充配置
|
|
88
|
-
// { text: "仓库地址", link: "https://github.com/ruan-cat/vercel-monorepo-test/tree/dev/packages/docs-01-star" },
|
|
89
|
-
],
|
|
86
|
+
nav: [{ text: "首页", link: "/" }],
|
|
90
87
|
|
|
91
88
|
outline: {
|
|
92
89
|
label: "本页目录",
|
|
@@ -99,7 +96,7 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
99
96
|
socialLinks: [
|
|
100
97
|
{
|
|
101
98
|
icon: "github",
|
|
102
|
-
link: "https://github.com/ruan-cat
|
|
99
|
+
link: "https://github.com/ruan-cat",
|
|
103
100
|
},
|
|
104
101
|
],
|
|
105
102
|
},
|
|
@@ -145,6 +142,20 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
145
142
|
config(md) {
|
|
146
143
|
md.use(vitepressDemoPlugin);
|
|
147
144
|
},
|
|
145
|
+
|
|
146
|
+
codeTransformers: [
|
|
147
|
+
// @ts-ignore FIXME: 这里出现奇怪的类型报错 屏蔽了
|
|
148
|
+
transformerTwoslash(),
|
|
149
|
+
],
|
|
150
|
+
// languages: ["js", "jsx", "ts", "tsx"],
|
|
151
|
+
|
|
152
|
+
container: {
|
|
153
|
+
tipLabel: "提示",
|
|
154
|
+
warningLabel: "警告",
|
|
155
|
+
dangerLabel: "危险",
|
|
156
|
+
infoLabel: "信息",
|
|
157
|
+
detailsLabel: "详情",
|
|
158
|
+
},
|
|
148
159
|
},
|
|
149
160
|
};
|
|
150
161
|
|
|
@@ -169,12 +180,13 @@ function handleChangeLog(userConfig: UserConfig<DefaultTheme.Config>) {
|
|
|
169
180
|
throw new Error(` nav 默认提供的导航栏配置为空。不符合默认配置,请检查。 `);
|
|
170
181
|
}
|
|
171
182
|
|
|
172
|
-
nav.push({
|
|
173
|
-
text: "变更日志",
|
|
174
|
-
link: "/CHANGELOG.md",
|
|
175
|
-
});
|
|
183
|
+
nav.push({ text: "更新日志", link: "/CHANGELOG.md" });
|
|
176
184
|
}
|
|
177
185
|
|
|
186
|
+
// function addTwoslashPlugin(userConfig: UserConfig<DefaultTheme.Config>) {
|
|
187
|
+
// userConfig.markdown?.codeTransformers?.push(transformerTwoslash());
|
|
188
|
+
// }
|
|
189
|
+
|
|
178
190
|
/** 设置vitepress主配置 */
|
|
179
191
|
export function setUserConfig(config?: UserConfig<DefaultTheme.Config>) {
|
|
180
192
|
/** 最终的用户数据 */
|