@ruan-cat/vitepress-preset-config 0.0.1 → 0.0.2

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 CHANGED
@@ -4,6 +4,7 @@ export { defineConfig } from 'vitepress';
4
4
  import { generateSidebar } from 'vitepress-sidebar';
5
5
  export { addChangelog2doc } from '@ruan-cat/utils/node-esm';
6
6
 
7
+ type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
7
8
  /**
8
9
  * 设置自动生成侧边栏的配置
9
10
  * @see https://vitepress-sidebar.cdget.com/zhHans/guide/options
@@ -11,6 +12,5 @@ export { addChangelog2doc } from '@ruan-cat/utils/node-esm';
11
12
  declare function setGenerateSidebar(options?: VitePressSidebarOptions): vitepress_sidebar_types.Sidebar;
12
13
  /** 设置vitepress主配置 */
13
14
  declare function setUserConfig(config?: UserConfig<DefaultTheme.Config>): UserConfig<DefaultTheme.Config>;
14
- type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
15
15
 
16
16
  export { setGenerateSidebar, setUserConfig };
package/dist/config.mjs CHANGED
@@ -4,7 +4,8 @@ import { generateSidebar } from "vitepress-sidebar";
4
4
  import { GitChangelog, GitChangelogMarkdownSection } from "@nolebase/vitepress-plugin-git-changelog/vite";
5
5
  import { vitepressDemoPlugin } from "vitepress-demo-plugin";
6
6
  import { merge, isUndefined, cloneDeep } from "lodash-es";
7
- import { addChangelog2doc } from "@ruan-cat/utils/node-esm";
7
+ import consola from "consola";
8
+ import { addChangelog2doc, hasChangelogMd } from "@ruan-cat/utils/node-esm";
8
9
  var defaultSidebarOptions = {
9
10
  // documentRootPath: "src",
10
11
  // 侧边栏需要折叠
@@ -103,8 +104,26 @@ var defaultUserConfig = {
103
104
  }
104
105
  }
105
106
  };
107
+ function handleChangeLog(userConfig) {
108
+ var _a;
109
+ if (!hasChangelogMd()) {
110
+ consola.warn(` \u672A\u627E\u5230\u53D8\u66F4\u65E5\u5FD7\u6587\u4EF6\uFF0C\u4E0D\u6DFB\u52A0\u53D8\u66F4\u65E5\u5FD7\u5BFC\u822A\u680F\u3002 `);
111
+ return;
112
+ }
113
+ const nav = (_a = userConfig == null ? void 0 : userConfig.themeConfig) == null ? void 0 : _a.nav;
114
+ if (isUndefined(nav)) {
115
+ consola.error(` \u5F53\u524D\u7684\u7528\u6237\u914D\u7F6E\u4E3A\uFF1A `, userConfig);
116
+ 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
+ }
118
+ nav.push({
119
+ text: "\u53D8\u66F4\u65E5\u5FD7",
120
+ link: "/CHANGELOG.md"
121
+ });
122
+ }
106
123
  function setUserConfig(config) {
107
- return merge({}, cloneDeep(defaultUserConfig), isUndefined(config) ? {} : config);
124
+ const resUserConfig = merge({}, cloneDeep(defaultUserConfig), isUndefined(config) ? {} : config);
125
+ handleChangeLog(resUserConfig);
126
+ return resUserConfig;
108
127
  }
109
128
  export {
110
129
  addChangelog2doc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruan-cat/vitepress-preset-config",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "用于给大多数的vitepress项目提供一个预设的配置文件。",
5
5
  "homepage": "https://utils.ruancat6312.top",
6
6
  "types": "./src/config.mts",
@@ -10,12 +10,13 @@
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
+ "consola": "^3.4.0",
13
14
  "js-yaml": "^4.1.0",
14
15
  "lodash-es": "^4.17.21",
15
16
  "vitepress-demo-plugin": "^1.3.1",
16
17
  "vitepress-sidebar": "^1.31.1",
17
18
  "vue": "^3.5.13",
18
- "@ruan-cat/utils": "^4.1.0"
19
+ "@ruan-cat/utils": "^4.1.1"
19
20
  },
20
21
  "devDependencies": {
21
22
  "@types/lodash-es": "^4.17.12",
package/src/config.mts CHANGED
@@ -7,10 +7,13 @@ import { GitChangelog, GitChangelogMarkdownSection } from "@nolebase/vitepress-p
7
7
  import { vitepressDemoPlugin } from "vitepress-demo-plugin";
8
8
 
9
9
  import { merge, isUndefined, cloneDeep } from "lodash-es";
10
+ import consola from "consola";
10
11
 
11
- import { addChangelog2doc } from "@ruan-cat/utils/node-esm";
12
+ import { addChangelog2doc, hasChangelogMd } from "@ruan-cat/utils/node-esm";
12
13
  export { addChangelog2doc };
13
14
 
15
+ type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
16
+
14
17
  /** 默认侧边栏配置 */
15
18
  const defaultSidebarOptions: VitePressSidebarOptions = {
16
19
  // documentRootPath: "src",
@@ -145,13 +148,40 @@ const defaultUserConfig: UserConfig<DefaultTheme.Config> = {
145
148
  },
146
149
  };
147
150
 
151
+ /**
152
+ * 设置导航栏的变更日志
153
+ * @description
154
+ * 在导航栏内添加一行 变更日志 的入口
155
+ *
156
+ * 直接修改外部传递进来的配置对象即可
157
+ * @private 内部使用即可
158
+ */
159
+ function handleChangeLog(userConfig: UserConfig<DefaultTheme.Config>) {
160
+ if (!hasChangelogMd()) {
161
+ consola.warn(` 未找到变更日志文件,不添加变更日志导航栏。 `);
162
+ return;
163
+ }
164
+
165
+ const nav = userConfig?.themeConfig?.nav;
166
+
167
+ if (isUndefined(nav)) {
168
+ consola.error(` 当前的用户配置为: `, userConfig);
169
+ throw new Error(` nav 默认提供的导航栏配置为空。不符合默认配置,请检查。 `);
170
+ }
171
+
172
+ nav.push({
173
+ text: "变更日志",
174
+ link: "/CHANGELOG.md",
175
+ });
176
+ }
177
+
148
178
  /** 设置vitepress主配置 */
149
179
  export function setUserConfig(config?: UserConfig<DefaultTheme.Config>) {
150
- return merge({}, cloneDeep(defaultUserConfig), isUndefined(config) ? {} : config);
151
- }
180
+ /** 最终的用户数据 */
181
+ const resUserConfig = merge({}, cloneDeep(defaultUserConfig), isUndefined(config) ? {} : config);
152
182
 
153
- type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
183
+ // 增加导航栏
184
+ handleChangeLog(resUserConfig);
154
185
 
155
- // TODO:
156
- /** 设置导航栏的变更日志 */
157
- function handleChangeLog() {}
186
+ return resUserConfig;
187
+ }