@ruan-cat/vitepress-preset-config 0.7.2 → 0.8.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/theme.d.mts CHANGED
@@ -2,36 +2,19 @@ import * as vue from 'vue';
2
2
  import { EnhanceAppContext } from 'vitepress';
3
3
 
4
4
  /**
5
- * 一个回调函数 用来暴露变量 实现注册\
6
- * @deprecated
5
+ * 一个回调函数 用来暴露变量 实现注册
7
6
  */
8
7
  interface EnhanceAppCallBack {
9
8
  ({ app, router, siteData }: EnhanceAppContext): void;
10
9
  }
11
10
  /**
12
- * @deprecated
13
11
  */
14
12
  interface DefineRuancatPresetThemeParams {
15
13
  enhanceAppCallBack?: EnhanceAppCallBack;
16
14
  }
17
- /**
18
- * 定义默认主题预设
19
- * @deprecated
20
- */
21
- declare function defineRuancatPresetTheme(params?: DefineRuancatPresetThemeParams): {
22
- extends: {
23
- Layout: vue.DefineComponent;
24
- enhanceApp: (ctx: EnhanceAppContext) => void;
25
- };
26
- Layout: () => vue.VNode<vue.RendererNode, vue.RendererElement, {
27
- [key: string]: any;
28
- }>;
29
- enhanceApp({ app, router, siteData }: EnhanceAppContext): void;
30
- };
31
15
  /**
32
16
  * 默认布局配置
33
17
  * @description
34
- * 有疑惑 经过测试 该写法会导致找不到主题文件
35
18
  */
36
19
  declare const defaultLayoutConfig: {
37
20
  "doc-before": () => vue.VNode<vue.RendererNode, vue.RendererElement, {
@@ -50,7 +33,8 @@ declare const defaultLayoutConfig: {
50
33
  /**
51
34
  * 默认 enhanceApp 预设
52
35
  * @description
53
- * 有疑惑 经过测试 该写法会导致找不到主题文件
36
+ * 这个函数预期应该作为一个内部函数 不应该对外暴露使用
37
+ * @private
54
38
  */
55
39
  declare function defaultEnhanceAppPreset({ app, router, siteData }: EnhanceAppContext): void;
56
40
  /** 默认主题配置 */
@@ -65,15 +49,17 @@ declare const defaultTheme: {
65
49
  enhanceApp({ app, router, siteData }: EnhanceAppContext): void;
66
50
  };
67
51
  /**
68
- * 默认主题配置2
69
- * @description
70
- * 从 @sugarat/theme 内学习的配置写法
52
+ * 定义默认主题预设
71
53
  */
72
- declare const defaultTheme2: {
54
+ declare function defineRuancatPresetTheme(params?: DefineRuancatPresetThemeParams): {
55
+ enhanceApp({ app, router, siteData }: EnhanceAppContext): void;
56
+ extends: {
57
+ Layout: vue.DefineComponent;
58
+ enhanceApp: (ctx: EnhanceAppContext) => void;
59
+ };
73
60
  Layout: () => vue.VNode<vue.RendererNode, vue.RendererElement, {
74
61
  [key: string]: any;
75
62
  }>;
76
- enhanceApp(ctx: EnhanceAppContext): void;
77
63
  };
78
64
 
79
- export { type DefineRuancatPresetThemeParams, type EnhanceAppCallBack, defaultEnhanceAppPreset, defaultLayoutConfig, defaultTheme, defaultTheme2, defineRuancatPresetTheme };
65
+ export { type DefineRuancatPresetThemeParams, type EnhanceAppCallBack, defaultEnhanceAppPreset, defaultLayoutConfig, defaultTheme, defineRuancatPresetTheme };
package/dist/theme.mjs CHANGED
@@ -11,38 +11,6 @@ import {
11
11
  import { NolebaseHighlightTargetedHeading } from "@nolebase/vitepress-plugin-highlight-targeted-heading/client";
12
12
  import { NolebaseGitChangelogPlugin } from "@nolebase/vitepress-plugin-git-changelog/client";
13
13
  import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
14
- function defineRuancatPresetTheme(params) {
15
- return {
16
- extends: DefaultTheme,
17
- Layout: () => {
18
- return h(DefaultTheme.Layout, null, {
19
- // https://vitepress.dev/guide/extending-default-theme#layout-slots
20
- "doc-before": () => h(NolebaseBreadcrumbs),
21
- "nav-bar-content-after": () => h(NolebaseEnhancedReadabilitiesMenu),
22
- // 为较窄的屏幕(通常是小于 iPad Mini)添加阅读增强菜单
23
- "nav-screen-content-after": () => h(NolebaseEnhancedReadabilitiesScreenMenu),
24
- "layout-top": () => [h(NolebaseHighlightTargetedHeading)]
25
- });
26
- },
27
- enhanceApp({ app, router, siteData }) {
28
- var _a;
29
- app.use(NolebaseGitChangelogPlugin);
30
- app.use(TwoslashFloatingVue);
31
- app.provide(InjectionKey, {
32
- layoutSwitch: {
33
- defaultMode: LayoutMode["BothWidthAdjustable"],
34
- pageLayoutMaxWidth: {
35
- defaultMaxWidth: 85
36
- },
37
- contentLayoutMaxWidth: {
38
- defaultMaxWidth: 95
39
- }
40
- }
41
- });
42
- (_a = params == null ? void 0 : params.enhanceAppCallBack) == null ? void 0 : _a.call(params, { app, router, siteData });
43
- }
44
- };
45
- }
46
14
  var defaultLayoutConfig = {
47
15
  // https://vitepress.dev/guide/extending-default-theme#layout-slots
48
16
  "doc-before": () => h(NolebaseBreadcrumbs),
@@ -75,39 +43,19 @@ var defaultTheme = {
75
43
  defaultEnhanceAppPreset({ app, router, siteData });
76
44
  }
77
45
  };
78
- var defaultTheme2 = {
79
- ...DefaultTheme,
80
- Layout: () => {
81
- return h(DefaultTheme.Layout, null, {
82
- // https://vitepress.dev/guide/extending-default-theme#layout-slots
83
- "doc-before": () => h(NolebaseBreadcrumbs),
84
- "nav-bar-content-after": () => h(NolebaseEnhancedReadabilitiesMenu),
85
- // 为较窄的屏幕(通常是小于 iPad Mini)添加阅读增强菜单
86
- "nav-screen-content-after": () => h(NolebaseEnhancedReadabilitiesScreenMenu),
87
- "layout-top": () => [h(NolebaseHighlightTargetedHeading)]
88
- });
89
- },
90
- enhanceApp(ctx) {
91
- DefaultTheme.enhanceApp(ctx);
92
- ctx.app.use(NolebaseGitChangelogPlugin);
93
- ctx.app.use(TwoslashFloatingVue);
94
- ctx.app.provide(InjectionKey, {
95
- layoutSwitch: {
96
- defaultMode: LayoutMode["BothWidthAdjustable"],
97
- pageLayoutMaxWidth: {
98
- defaultMaxWidth: 85
99
- },
100
- contentLayoutMaxWidth: {
101
- defaultMaxWidth: 95
102
- }
103
- }
104
- });
105
- }
106
- };
46
+ function defineRuancatPresetTheme(params) {
47
+ return {
48
+ ...defaultTheme,
49
+ enhanceApp({ app, router, siteData }) {
50
+ var _a;
51
+ defaultTheme.enhanceApp({ app, router, siteData });
52
+ (_a = params == null ? void 0 : params.enhanceAppCallBack) == null ? void 0 : _a.call(params, { app, router, siteData });
53
+ }
54
+ };
55
+ }
107
56
  export {
108
57
  defaultEnhanceAppPreset,
109
58
  defaultLayoutConfig,
110
59
  defaultTheme,
111
- defaultTheme2,
112
60
  defineRuancatPresetTheme
113
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruan-cat/vitepress-preset-config",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "用于给大多数的vitepress项目提供一个预设的配置文件。",
5
5
  "homepage": "https://vitepress-preset.ruancat6312.top",
6
6
  "types": "./src/config.mts",
@@ -54,7 +54,7 @@
54
54
  "types": "./src/config.mts"
55
55
  },
56
56
  "./theme": {
57
- "import": "./dist/theme.mjs",
57
+ "import": "./src/theme.ts",
58
58
  "types": "./src/theme.ts"
59
59
  },
60
60
  "./theme.css": "./dist/theme.css",
@@ -1,7 +1,7 @@
1
1
  // 避免直接使用自己的包
2
2
  // import { setUserConfig, setGenerateSidebar, addChangelog2doc } from "@ruan-cat/vitepress-preset-config/config";
3
3
  // @ts-ignore
4
- import { setUserConfig, setGenerateSidebar, addChangelog2doc } from "../../src/config.mts";
4
+ import { setUserConfig, setGenerateSidebar, addChangelog2doc } from "../config.mts";
5
5
  import { description } from "../../package.json";
6
6
 
7
7
  addChangelog2doc({
@@ -1,18 +1,9 @@
1
- // https://vitepress.dev/guide/custom-theme
2
- import { h } from "vue";
3
- import type { Theme, EnhanceAppContext } from "vitepress";
4
- import DefaultTheme from "vitepress/theme";
5
- import { defaultLayoutConfig, defaultEnhanceAppPreset } from "@ruan-cat/vitepress-preset-config/theme";
1
+ import { defineRuancatPresetTheme } from "@ruan-cat/vitepress-preset-config/theme";
6
2
 
7
3
  // 导入全部的主题样式
8
4
  import "@ruan-cat/vitepress-preset-config/theme.css";
5
+
6
+ // 增加用户自定义样式
9
7
  import "./style.css";
10
- export default {
11
- extends: DefaultTheme,
12
- Layout: () => {
13
- return h(DefaultTheme.Layout, null, defaultLayoutConfig);
14
- },
15
- enhanceApp({ app, router, siteData }: EnhanceAppContext) {
16
- defaultEnhanceAppPreset({ app, router, siteData });
17
- },
18
- } satisfies Theme;
8
+
9
+ export default defineRuancatPresetTheme();
package/src/theme.ts CHANGED
@@ -15,7 +15,6 @@ import { NolebaseBreadcrumbs } from "@nolebase/vitepress-plugin-breadcrumbs/clie
15
15
  import {
16
16
  NolebaseEnhancedReadabilitiesMenu,
17
17
  NolebaseEnhancedReadabilitiesScreenMenu,
18
-
19
18
  // https://nolebase-integrations.ayaka.io/pages/zh-CN/integrations/vitepress-plugin-enhanced-readabilities/#如何在-vitepress-中进行配置
20
19
  InjectionKey,
21
20
  type Options,
@@ -33,68 +32,21 @@ import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
33
32
  // import "@shikijs/vitepress-twoslash/style.css";
34
33
 
35
34
  /**
36
- * 一个回调函数 用来暴露变量 实现注册\
37
- * @deprecated
35
+ * 一个回调函数 用来暴露变量 实现注册
38
36
  */
39
37
  export interface EnhanceAppCallBack {
40
38
  ({ app, router, siteData }: EnhanceAppContext): void;
41
39
  }
42
40
 
43
41
  /**
44
- * @deprecated
45
42
  */
46
43
  export interface DefineRuancatPresetThemeParams {
47
44
  enhanceAppCallBack?: EnhanceAppCallBack;
48
45
  }
49
46
 
50
- /**
51
- * 定义默认主题预设
52
- * @deprecated
53
- */
54
- export function defineRuancatPresetTheme(params?: DefineRuancatPresetThemeParams) {
55
- return {
56
- extends: DefaultTheme,
57
- Layout: () => {
58
- return h(DefaultTheme.Layout, null, {
59
- // https://vitepress.dev/guide/extending-default-theme#layout-slots
60
- "doc-before": () => h(NolebaseBreadcrumbs),
61
- "nav-bar-content-after": () => h(NolebaseEnhancedReadabilitiesMenu),
62
- // 为较窄的屏幕(通常是小于 iPad Mini)添加阅读增强菜单
63
- "nav-screen-content-after": () => h(NolebaseEnhancedReadabilitiesScreenMenu),
64
- "layout-top": () => [h(NolebaseHighlightTargetedHeading)],
65
- });
66
- },
67
- enhanceApp({ app, router, siteData }: EnhanceAppContext) {
68
- app.use(NolebaseGitChangelogPlugin);
69
- app.use(TwoslashFloatingVue);
70
- app.provide(InjectionKey, {
71
- layoutSwitch: {
72
- defaultMode: LayoutMode["BothWidthAdjustable"],
73
- pageLayoutMaxWidth: {
74
- defaultMaxWidth: 85,
75
- },
76
- contentLayoutMaxWidth: {
77
- defaultMaxWidth: 95,
78
- },
79
- },
80
- } as Options);
81
-
82
- /**
83
- * 放弃全局注册demo展示组件
84
- * 在生产环境内使用peer对等依赖
85
- */
86
- // app.component("VitepressDemoBox", VitepressDemoBox);
87
- // app.component("VitepressDemoPlaceholder", VitepressDemoPlaceholder);
88
-
89
- params?.enhanceAppCallBack?.({ app, router, siteData });
90
- },
91
- } satisfies Theme;
92
- }
93
-
94
47
  /**
95
48
  * 默认布局配置
96
49
  * @description
97
- * 有疑惑 经过测试 该写法会导致找不到主题文件
98
50
  */
99
51
  export const defaultLayoutConfig = {
100
52
  // https://vitepress.dev/guide/extending-default-theme#layout-slots
@@ -108,7 +60,8 @@ export const defaultLayoutConfig = {
108
60
  /**
109
61
  * 默认 enhanceApp 预设
110
62
  * @description
111
- * 有疑惑 经过测试 该写法会导致找不到主题文件
63
+ * 这个函数预期应该作为一个内部函数 不应该对外暴露使用
64
+ * @private
112
65
  */
113
66
  export function defaultEnhanceAppPreset({ app, router, siteData }: EnhanceAppContext) {
114
67
  app.use(NolebaseGitChangelogPlugin);
@@ -124,6 +77,12 @@ export function defaultEnhanceAppPreset({ app, router, siteData }: EnhanceAppCon
124
77
  },
125
78
  },
126
79
  } as Options);
80
+ /**
81
+ * 放弃全局注册demo展示组件
82
+ * 在生产环境内使用peer对等依赖
83
+ */
84
+ // app.component("VitepressDemoBox", VitepressDemoBox);
85
+ // app.component("VitepressDemoPlaceholder", VitepressDemoPlaceholder);
127
86
  }
128
87
 
129
88
  /** 默认主题配置 */
@@ -134,47 +93,20 @@ export const defaultTheme = {
134
93
  },
135
94
  enhanceApp({ app, router, siteData }: EnhanceAppContext) {
136
95
  defaultEnhanceAppPreset({ app, router, siteData });
137
- /**
138
- * 放弃全局注册demo展示组件
139
- * 在生产环境内使用peer对等依赖
140
- */
141
- // app.component("VitepressDemoBox", VitepressDemoBox);
142
- // app.component("VitepressDemoPlaceholder", VitepressDemoPlaceholder);
143
96
  },
144
97
  } satisfies Theme;
145
98
 
146
99
  /**
147
- * 默认主题配置2
148
- * @description
149
- * 从 @sugarat/theme 内学习的配置写法
100
+ * 定义默认主题预设
150
101
  */
151
- export const defaultTheme2 = {
152
- ...DefaultTheme,
153
- Layout: () => {
154
- return h(DefaultTheme.Layout, null, {
155
- // https://vitepress.dev/guide/extending-default-theme#layout-slots
156
- "doc-before": () => h(NolebaseBreadcrumbs),
157
- "nav-bar-content-after": () => h(NolebaseEnhancedReadabilitiesMenu),
158
- // 为较窄的屏幕(通常是小于 iPad Mini)添加阅读增强菜单
159
- "nav-screen-content-after": () => h(NolebaseEnhancedReadabilitiesScreenMenu),
160
- "layout-top": () => [h(NolebaseHighlightTargetedHeading)],
161
- });
162
- },
163
- enhanceApp(ctx: EnhanceAppContext) {
164
- DefaultTheme.enhanceApp(ctx);
165
-
166
- ctx.app.use(NolebaseGitChangelogPlugin);
167
- ctx.app.use(TwoslashFloatingVue);
168
- ctx.app.provide(InjectionKey, {
169
- layoutSwitch: {
170
- defaultMode: LayoutMode["BothWidthAdjustable"],
171
- pageLayoutMaxWidth: {
172
- defaultMaxWidth: 85,
173
- },
174
- contentLayoutMaxWidth: {
175
- defaultMaxWidth: 95,
176
- },
177
- },
178
- } as Options);
179
- },
180
- } satisfies Theme;
102
+ export function defineRuancatPresetTheme(params?: DefineRuancatPresetThemeParams) {
103
+ return {
104
+ ...defaultTheme,
105
+ enhanceApp({ app, router, siteData }: EnhanceAppContext) {
106
+ // 回调默认主题内的函数
107
+ defaultTheme.enhanceApp({ app, router, siteData });
108
+ // 执行用户传入的回调函数
109
+ params?.enhanceAppCallBack?.({ app, router, siteData });
110
+ },
111
+ } satisfies Theme;
112
+ }