@ruan-cat/vitepress-preset-config 1.4.0 → 2.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.d.mts +42 -1
- package/dist/config.mjs +70 -40
- package/dist/theme.d.mts +0 -2
- package/dist/theme.mjs +4 -1
- package/package.json +1 -1
- 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 +32 -76
- package/src/index.ts +6 -0
- package/src/theme.ts +8 -2
- package/src/types.ts +49 -0
package/dist/config.d.mts
CHANGED
|
@@ -2,8 +2,49 @@ 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
|
+
}
|
|
47
|
+
|
|
7
48
|
type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
|
|
8
49
|
/**
|
|
9
50
|
* 设置自动生成侧边栏的配置
|
|
@@ -11,6 +52,6 @@ type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
|
|
|
11
52
|
*/
|
|
12
53
|
declare function setGenerateSidebar(options?: VitePressSidebarOptions): vitepress_sidebar_types.Sidebar;
|
|
13
54
|
/** 设置vitepress主配置 */
|
|
14
|
-
declare function setUserConfig(config?: UserConfig<DefaultTheme.Config
|
|
55
|
+
declare function setUserConfig(config?: UserConfig<DefaultTheme.Config>, extraConfig?: ExtraConfig): UserConfig<DefaultTheme.Config>;
|
|
15
56
|
|
|
16
57
|
export { setGenerateSidebar, setUserConfig };
|
package/dist/config.mjs
CHANGED
|
@@ -1,16 +1,51 @@
|
|
|
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
|
-
import
|
|
11
|
-
|
|
9
|
+
import { copyOrDownloadAsMarkdownButtons } from "vitepress-plugin-llms";
|
|
10
|
+
|
|
11
|
+
// src/config/plugins.ts
|
|
12
|
+
import vitepressPluginLlmstxt from "vitepress-plugin-llms";
|
|
13
|
+
import { GitChangelog, GitChangelogMarkdownSection } from "@nolebase/vitepress-plugin-git-changelog/vite";
|
|
14
|
+
function isFalse(value) {
|
|
15
|
+
return value === false;
|
|
16
|
+
}
|
|
17
|
+
var defaultGitChangelogOptions = {
|
|
18
|
+
// 填写在此处填写您的仓库链接
|
|
19
|
+
repoURL: () => "https://github.com/ruan-cat/monorepo",
|
|
20
|
+
// 最大日志深度为10, 避免获取过多无意义的历史日志
|
|
21
|
+
maxGitLogCount: 10
|
|
22
|
+
};
|
|
23
|
+
function getPlugins(extraConfig) {
|
|
24
|
+
const plugins = [];
|
|
25
|
+
const {
|
|
26
|
+
llmstxt: llmstxt2,
|
|
27
|
+
gitChangelog = defaultGitChangelogOptions,
|
|
28
|
+
gitChangelogMarkdownSection
|
|
29
|
+
} = (extraConfig == null ? void 0 : extraConfig.plugins) || {};
|
|
30
|
+
if (!isFalse(llmstxt2)) {
|
|
31
|
+
plugins.push(vitepressPluginLlmstxt(llmstxt2));
|
|
32
|
+
}
|
|
33
|
+
if (!isFalse(gitChangelog)) {
|
|
34
|
+
plugins.push(GitChangelog(gitChangelog));
|
|
35
|
+
}
|
|
36
|
+
if (!isFalse(gitChangelogMarkdownSection)) {
|
|
37
|
+
plugins.push(GitChangelogMarkdownSection(gitChangelogMarkdownSection));
|
|
38
|
+
}
|
|
39
|
+
return plugins;
|
|
40
|
+
}
|
|
41
|
+
function handlePlugins(userConfig, extraConfig) {
|
|
42
|
+
userConfig.vite.plugins = getPlugins(extraConfig);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/config/teek.ts
|
|
12
46
|
import { defineTeekConfig } from "vitepress-theme-teek/config";
|
|
13
|
-
|
|
47
|
+
import { merge, cloneDeep } from "lodash-es";
|
|
48
|
+
var defaultTeekConfig = {
|
|
14
49
|
/** @see https://vp.teek.top/reference/config/global-config.html#sidebartrigger */
|
|
15
50
|
sidebarTrigger: true,
|
|
16
51
|
/**
|
|
@@ -48,7 +83,15 @@ var teekConfig = defineTeekConfig({
|
|
|
48
83
|
hash: false
|
|
49
84
|
// 是否包含哈希值
|
|
50
85
|
}
|
|
51
|
-
}
|
|
86
|
+
};
|
|
87
|
+
function handleTeekConfig(userConfig, extraConfig) {
|
|
88
|
+
const { teekConfig = defaultTeekConfig } = extraConfig ?? {};
|
|
89
|
+
userConfig.extends = defineTeekConfig(merge({}, cloneDeep(defaultTeekConfig), teekConfig));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/config.mts
|
|
93
|
+
import { MermaidPlugin } from "@leelaa/vitepress-plugin-extended";
|
|
94
|
+
import { defineTeekConfig as defineTeekConfig2 } from "vitepress-theme-teek/config";
|
|
52
95
|
var defaultSidebarOptions = {
|
|
53
96
|
// documentRootPath: "src",
|
|
54
97
|
// 侧边栏需要折叠
|
|
@@ -75,13 +118,17 @@ var defaultSidebarOptions = {
|
|
|
75
118
|
debugPrint: false
|
|
76
119
|
};
|
|
77
120
|
function getMergeSidebarOptions(options) {
|
|
78
|
-
return
|
|
121
|
+
return merge2({}, cloneDeep2(defaultSidebarOptions), isUndefined(options) ? {} : options);
|
|
79
122
|
}
|
|
80
123
|
function setGenerateSidebar(options) {
|
|
81
124
|
return generateSidebar(getMergeSidebarOptions(options));
|
|
82
125
|
}
|
|
83
126
|
var defaultUserConfig = {
|
|
84
|
-
|
|
127
|
+
/**
|
|
128
|
+
* 使用默认的 Teek 主题配置
|
|
129
|
+
* 后续会有函数重新设置 Teek 主题配置,并覆盖默认配置
|
|
130
|
+
*/
|
|
131
|
+
extends: defineTeekConfig2(defaultTeekConfig),
|
|
85
132
|
title: "\u8BF7\u586B\u5199\u6709\u610F\u4E49\u7684\u6807\u9898",
|
|
86
133
|
description: "\u8BF7\u586B\u5199\u6709\u610F\u4E49\u7684\u63CF\u8FF0",
|
|
87
134
|
lang: "zh",
|
|
@@ -89,9 +136,7 @@ var defaultUserConfig = {
|
|
|
89
136
|
// srcDir: "./src",
|
|
90
137
|
themeConfig: {
|
|
91
138
|
i18nRouting: true,
|
|
92
|
-
search: {
|
|
93
|
-
provider: "local"
|
|
94
|
-
},
|
|
139
|
+
search: { provider: "local" },
|
|
95
140
|
// https://vitepress.dev/reference/default-theme-config
|
|
96
141
|
nav: [{ text: "\u9996\u9875", link: "/" }],
|
|
97
142
|
outline: {
|
|
@@ -100,35 +145,17 @@ var defaultUserConfig = {
|
|
|
100
145
|
},
|
|
101
146
|
// 自动化侧边栏
|
|
102
147
|
sidebar: setGenerateSidebar(),
|
|
103
|
-
socialLinks: [
|
|
104
|
-
{
|
|
105
|
-
icon: "github",
|
|
106
|
-
link: "https://github.com/ruan-cat"
|
|
107
|
-
}
|
|
108
|
-
]
|
|
148
|
+
socialLinks: [{ icon: "github", link: "https://github.com/ruan-cat" }]
|
|
109
149
|
},
|
|
110
150
|
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
|
-
},
|
|
151
|
+
server: { open: true, port: 8080 },
|
|
152
|
+
/**
|
|
153
|
+
* 插件
|
|
154
|
+
* @description
|
|
155
|
+
* 这里留空 插件在 config/plugins.ts 中配置
|
|
156
|
+
*/
|
|
157
|
+
plugins: [],
|
|
158
|
+
optimizeDeps: { exclude: ["vitepress", "@nolebase/ui"] },
|
|
132
159
|
ssr: {
|
|
133
160
|
noExternal: [
|
|
134
161
|
// 如果还有别的依赖需要添加的话,并排填写和配置到这里即可
|
|
@@ -140,6 +167,7 @@ var defaultUserConfig = {
|
|
|
140
167
|
config(md) {
|
|
141
168
|
md.use(vitepressDemoPlugin);
|
|
142
169
|
MermaidPlugin(md);
|
|
170
|
+
md.use(copyOrDownloadAsMarkdownButtons);
|
|
143
171
|
},
|
|
144
172
|
codeTransformers: [
|
|
145
173
|
// @ts-ignore FIXME: 这里出现奇怪的类型报错 屏蔽了
|
|
@@ -176,9 +204,11 @@ function handleChangeLog(userConfig) {
|
|
|
176
204
|
}
|
|
177
205
|
nav.push({ text: "\u66F4\u65B0\u65E5\u5FD7", link: "/CHANGELOG.md" });
|
|
178
206
|
}
|
|
179
|
-
function setUserConfig(config) {
|
|
180
|
-
const resUserConfig =
|
|
207
|
+
function setUserConfig(config, extraConfig) {
|
|
208
|
+
const resUserConfig = merge2({}, cloneDeep2(defaultUserConfig), isUndefined(config) ? {} : config);
|
|
181
209
|
handleChangeLog(resUserConfig);
|
|
210
|
+
handlePlugins(resUserConfig, extraConfig);
|
|
211
|
+
handleTeekConfig(resUserConfig, extraConfig);
|
|
182
212
|
return resUserConfig;
|
|
183
213
|
}
|
|
184
214
|
export {
|
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
|
@@ -3,6 +3,7 @@ import { NolebaseGitChangelogPlugin } from "@nolebase/vitepress-plugin-git-chang
|
|
|
3
3
|
import "@nolebase/vitepress-plugin-git-changelog/client/style.css";
|
|
4
4
|
import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
|
|
5
5
|
import "@shikijs/vitepress-twoslash/style.css";
|
|
6
|
+
import CopyOrDownloadAsMarkdownButtons from "vitepress-plugin-llms/vitepress-components/CopyOrDownloadAsMarkdownButtons.vue";
|
|
6
7
|
import Teek from "vitepress-theme-teek";
|
|
7
8
|
import "vitepress-theme-teek/index.css";
|
|
8
9
|
import { Mermaid } from "@leelaa/vitepress-plugin-extended";
|
|
@@ -10,10 +11,12 @@ function defaultEnhanceAppPreset({ app, router, siteData }) {
|
|
|
10
11
|
app.use(NolebaseGitChangelogPlugin);
|
|
11
12
|
app.use(TwoslashFloatingVue);
|
|
12
13
|
app.component("Mermaid", Mermaid);
|
|
14
|
+
app.component("CopyOrDownloadAsMarkdownButtons", CopyOrDownloadAsMarkdownButtons);
|
|
13
15
|
}
|
|
14
16
|
var defaultTheme = {
|
|
15
17
|
extends: Teek,
|
|
16
|
-
|
|
18
|
+
// 有疑惑 根据和 teek 作者的沟通 这个配置可以不写
|
|
19
|
+
// Layout: Teek.Layout,
|
|
17
20
|
enhanceApp({ app, router, siteData }) {
|
|
18
21
|
defaultEnhanceAppPreset({ app, router, siteData });
|
|
19
22
|
}
|
package/package.json
CHANGED
|
@@ -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,13 +7,16 @@ 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 };
|
|
13
14
|
|
|
14
15
|
import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
|
|
15
16
|
|
|
16
|
-
import llmstxt from "vitepress-plugin-llms";
|
|
17
|
+
import llmstxt, { copyOrDownloadAsMarkdownButtons } from "vitepress-plugin-llms";
|
|
18
|
+
|
|
19
|
+
import { defaultTeekConfig, handleTeekConfig, handlePlugins } from "./config/index.ts";
|
|
17
20
|
|
|
18
21
|
/** @see https://vitepress-ext.leelaa.cn/Mermaid.html#扩展-md-插件 */
|
|
19
22
|
import { MermaidPlugin } from "@leelaa/vitepress-plugin-extended";
|
|
@@ -21,47 +24,6 @@ import { MermaidPlugin } from "@leelaa/vitepress-plugin-extended";
|
|
|
21
24
|
// https://vp.teek.top/guide/quickstart.html#teek-引入
|
|
22
25
|
import { defineTeekConfig } from "vitepress-theme-teek/config";
|
|
23
26
|
|
|
24
|
-
/** Teek 主题配置 */
|
|
25
|
-
const teekConfig = defineTeekConfig({
|
|
26
|
-
/** @see https://vp.teek.top/reference/config/global-config.html#sidebartrigger */
|
|
27
|
-
sidebarTrigger: true,
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 关闭 Teek 主题的首页风格
|
|
31
|
-
* @see https://vp.teek.top/reference/config/global-config.html#teekhome
|
|
32
|
-
*/
|
|
33
|
-
teekHome: false,
|
|
34
|
-
|
|
35
|
-
vitePlugins: {
|
|
36
|
-
/**
|
|
37
|
-
* 关闭 vitepress-plugin-permalink 插件
|
|
38
|
-
* @see https://vp.teek.top/guide/plugins.html#vitepress-plugin-permalink
|
|
39
|
-
*/
|
|
40
|
-
permalink: false,
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 关闭 vitepress-plugin-sidebar-resolve 插件
|
|
44
|
-
* @see https://vp.teek.top/guide/plugins.html#vitepress-plugin-sidebar-resolve
|
|
45
|
-
*/
|
|
46
|
-
sidebar: false,
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 关闭 vitepress-plugin-md-h1 插件
|
|
50
|
-
* @see https://vp.teek.top/guide/plugins.html#vitepress-plugin-md-h1
|
|
51
|
-
*/
|
|
52
|
-
mdH1: false,
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
/** @see https://vp.teek.top/reference/article-config.html#articleshare */
|
|
56
|
-
articleShare: {
|
|
57
|
-
enabled: true, // 是否开启文章链接分享功能
|
|
58
|
-
text: "分享此页面", // 分享按钮文本
|
|
59
|
-
copiedText: "链接已复制", // 复制成功文本
|
|
60
|
-
query: false, // 是否包含查询参数
|
|
61
|
-
hash: false, // 是否包含哈希值
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
27
|
type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
|
|
66
28
|
|
|
67
29
|
/** 默认侧边栏配置 */
|
|
@@ -117,7 +79,11 @@ export function setGenerateSidebar(options?: VitePressSidebarOptions) {
|
|
|
117
79
|
|
|
118
80
|
/** 默认用户配置 */
|
|
119
81
|
const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
120
|
-
|
|
82
|
+
/**
|
|
83
|
+
* 使用默认的 Teek 主题配置
|
|
84
|
+
* 后续会有函数重新设置 Teek 主题配置,并覆盖默认配置
|
|
85
|
+
*/
|
|
86
|
+
extends: defineTeekConfig(defaultTeekConfig),
|
|
121
87
|
|
|
122
88
|
title: "请填写有意义的标题",
|
|
123
89
|
description: "请填写有意义的描述",
|
|
@@ -129,9 +95,7 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
129
95
|
themeConfig: {
|
|
130
96
|
i18nRouting: true,
|
|
131
97
|
|
|
132
|
-
search: {
|
|
133
|
-
provider: "local",
|
|
134
|
-
},
|
|
98
|
+
search: { provider: "local" },
|
|
135
99
|
|
|
136
100
|
// https://vitepress.dev/reference/default-theme-config
|
|
137
101
|
nav: [{ text: "首页", link: "/" }],
|
|
@@ -144,40 +108,20 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
144
108
|
// 自动化侧边栏
|
|
145
109
|
sidebar: setGenerateSidebar(),
|
|
146
110
|
|
|
147
|
-
socialLinks: [
|
|
148
|
-
{
|
|
149
|
-
icon: "github",
|
|
150
|
-
link: "https://github.com/ruan-cat",
|
|
151
|
-
},
|
|
152
|
-
],
|
|
111
|
+
socialLinks: [{ icon: "github", link: "https://github.com/ruan-cat" }],
|
|
153
112
|
},
|
|
154
113
|
|
|
155
114
|
vite: {
|
|
156
|
-
server: {
|
|
157
|
-
open: true,
|
|
158
|
-
port: 8080,
|
|
159
|
-
},
|
|
115
|
+
server: { open: true, port: 8080 },
|
|
160
116
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
GitChangelog({
|
|
168
|
-
// 填写在此处填写您的仓库链接
|
|
169
|
-
repoURL: () => "https://github.com/ruan-cat/monorepo",
|
|
170
|
-
// 最大日志深度为10, 避免获取过多无意义的历史日志
|
|
171
|
-
maxGitLogCount: 10,
|
|
172
|
-
}),
|
|
173
|
-
|
|
174
|
-
// @ts-ignore
|
|
175
|
-
GitChangelogMarkdownSection(),
|
|
176
|
-
],
|
|
117
|
+
/**
|
|
118
|
+
* 插件
|
|
119
|
+
* @description
|
|
120
|
+
* 这里留空 插件在 config/plugins.ts 中配置
|
|
121
|
+
*/
|
|
122
|
+
plugins: [],
|
|
177
123
|
|
|
178
|
-
optimizeDeps: {
|
|
179
|
-
exclude: ["vitepress", "@nolebase/ui"],
|
|
180
|
-
},
|
|
124
|
+
optimizeDeps: { exclude: ["vitepress", "@nolebase/ui"] },
|
|
181
125
|
|
|
182
126
|
ssr: {
|
|
183
127
|
noExternal: [
|
|
@@ -193,6 +137,9 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
|
|
|
193
137
|
|
|
194
138
|
// @ts-ignore
|
|
195
139
|
MermaidPlugin(md);
|
|
140
|
+
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
md.use(copyOrDownloadAsMarkdownButtons);
|
|
196
143
|
},
|
|
197
144
|
|
|
198
145
|
codeTransformers: [
|
|
@@ -246,12 +193,21 @@ function handleChangeLog(userConfig: UserConfig<DefaultTheme.Config>) {
|
|
|
246
193
|
}
|
|
247
194
|
|
|
248
195
|
/** 设置vitepress主配置 */
|
|
249
|
-
export function setUserConfig(
|
|
196
|
+
export function setUserConfig(
|
|
197
|
+
config?: UserConfig<DefaultTheme.Config>,
|
|
198
|
+
extraConfig?: ExtraConfig,
|
|
199
|
+
): UserConfig<DefaultTheme.Config> {
|
|
250
200
|
/** 最终的用户数据 */
|
|
251
201
|
const resUserConfig = merge({}, cloneDeep(defaultUserConfig), isUndefined(config) ? {} : config);
|
|
252
202
|
|
|
253
203
|
// 增加导航栏
|
|
254
204
|
handleChangeLog(resUserConfig);
|
|
255
205
|
|
|
206
|
+
// 设置插件
|
|
207
|
+
handlePlugins(resUserConfig, extraConfig);
|
|
208
|
+
|
|
209
|
+
// 设置 Teek 主题配置
|
|
210
|
+
handleTeekConfig(resUserConfig, extraConfig);
|
|
211
|
+
|
|
256
212
|
return resUserConfig;
|
|
257
213
|
}
|
package/src/index.ts
ADDED
package/src/theme.ts
CHANGED
|
@@ -13,12 +13,16 @@ import "@nolebase/vitepress-plugin-git-changelog/client/style.css";
|
|
|
13
13
|
import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
|
|
14
14
|
import "@shikijs/vitepress-twoslash/style.css";
|
|
15
15
|
|
|
16
|
+
/** @see https://github.com/okineadev/vitepress-plugin-llms/blob/main/README.md */
|
|
17
|
+
// @ts-ignore FIXME: 该组件直接使用时没有故障的 但是tsup打包有故障 故忽略类型报错
|
|
18
|
+
import CopyOrDownloadAsMarkdownButtons from "vitepress-plugin-llms/vitepress-components/CopyOrDownloadAsMarkdownButtons.vue";
|
|
19
|
+
|
|
16
20
|
// https://vp.teek.top/guide/quickstart.html#teek-引入
|
|
17
21
|
import Teek from "vitepress-theme-teek";
|
|
18
22
|
import "vitepress-theme-teek/index.css";
|
|
19
23
|
|
|
20
24
|
/** @see https://vitepress-ext.leelaa.cn/Mermaid.html#全局引入 */
|
|
21
|
-
// @ts-ignore
|
|
25
|
+
// @ts-ignore FIXME: 忽略类型导出的bug 避免tsup打包失败
|
|
22
26
|
import { Mermaid } from "@leelaa/vitepress-plugin-extended";
|
|
23
27
|
|
|
24
28
|
/**
|
|
@@ -44,6 +48,7 @@ function defaultEnhanceAppPreset({ app, router, siteData }: EnhanceAppContext) {
|
|
|
44
48
|
app.use(NolebaseGitChangelogPlugin);
|
|
45
49
|
app.use(TwoslashFloatingVue);
|
|
46
50
|
app.component("Mermaid", Mermaid);
|
|
51
|
+
app.component("CopyOrDownloadAsMarkdownButtons", CopyOrDownloadAsMarkdownButtons);
|
|
47
52
|
/**
|
|
48
53
|
* 放弃全局注册demo展示组件
|
|
49
54
|
* 在生产环境内使用peer对等依赖
|
|
@@ -55,7 +60,8 @@ function defaultEnhanceAppPreset({ app, router, siteData }: EnhanceAppContext) {
|
|
|
55
60
|
/** 默认主题配置 */
|
|
56
61
|
export const defaultTheme = {
|
|
57
62
|
extends: Teek,
|
|
58
|
-
|
|
63
|
+
// 有疑惑 根据和 teek 作者的沟通 这个配置可以不写
|
|
64
|
+
// Layout: Teek.Layout,
|
|
59
65
|
enhanceApp({ app, router, siteData }: EnhanceAppContext) {
|
|
60
66
|
defaultEnhanceAppPreset({ app, router, siteData });
|
|
61
67
|
},
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import llmstxt from "vitepress-plugin-llms";
|
|
2
|
+
import { GitChangelog, type GitChangelogMarkdownSectionOptions } from "@nolebase/vitepress-plugin-git-changelog/vite";
|
|
3
|
+
|
|
4
|
+
// https://vp.teek.top/guide/quickstart.html#teek-引入
|
|
5
|
+
import { defineTeekConfig } from "vitepress-theme-teek/config";
|
|
6
|
+
|
|
7
|
+
export type LlmstxtSettings = NonNullable<Parameters<typeof llmstxt>[0]>;
|
|
8
|
+
|
|
9
|
+
export type GitChangelogOptions = NonNullable<Parameters<typeof GitChangelog>[0]>;
|
|
10
|
+
|
|
11
|
+
export type TeekConfigOptions = NonNullable<Parameters<typeof defineTeekConfig>[0]>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 额外的配置
|
|
15
|
+
* @description
|
|
16
|
+
* 目前主要用于精细化配置 vitepress 的插件
|
|
17
|
+
*/
|
|
18
|
+
export 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
|
+
/**
|
|
32
|
+
* @description 用于配置 @nolebase/vitepress-plugin-git-changelog 插件
|
|
33
|
+
* @see
|
|
34
|
+
*/
|
|
35
|
+
gitChangelog?: GitChangelogOptions | false;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @description 用于配置 @nolebase/vitepress-plugin-git-changelog-markdown-section 插件
|
|
39
|
+
* @see
|
|
40
|
+
*/
|
|
41
|
+
gitChangelogMarkdownSection?: GitChangelogMarkdownSectionOptions | false;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Teek 主题配置
|
|
46
|
+
* @see https://vp.teek.top/reference/config.html
|
|
47
|
+
*/
|
|
48
|
+
teekConfig?: TeekConfigOptions;
|
|
49
|
+
}
|