@alauda/doom 0.23.2 → 0.23.3

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.
@@ -111,6 +111,7 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
111
111
  lang: fallbackToZh ? 'zh' : config.lang || 'en',
112
112
  title: '',
113
113
  route: {
114
+ include: ignore ? config.onlyIncludeRoutes : undefined,
114
115
  exclude: [
115
116
  'dist/**/*',
116
117
  'public/**/*',
@@ -118,6 +119,7 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
118
119
  'doom.config.*',
119
120
  '**/assets/**/*',
120
121
  '**/*.d.ts',
122
+ ...((ignore && config.internalRoutes) || []),
121
123
  ...unusedLanguages.map((lang) => `${lang}/**/*`),
122
124
  ],
123
125
  },
@@ -106,6 +106,7 @@ export const translate = async ({ source, sourceContent, target, targetContent =
106
106
  },
107
107
  ],
108
108
  model: 'gpt-4o-mini',
109
+ temperature: 0,
109
110
  });
110
111
  const { content, refusal } = choices[0].message;
111
112
  if (refusal) {
@@ -141,21 +141,22 @@ import { walk } from './walk.js';
141
141
  // }
142
142
  // ]
143
143
  // ```
144
- function processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, excludeRoutes, collapsed) {
144
+ function processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, onlyIncludeRoutes, excludeRoutes, collapsed) {
145
145
  return Promise.all(langs.map(async (lang) => {
146
146
  const walks = versions.length
147
147
  ? await Promise.all(versions.map((version) => {
148
148
  const routePrefix = addTrailingSlash(`${version === defaultVersion ? '' : `/${version}`}${lang === defaultLang ? '' : `/${lang}`}`);
149
- return walk(path.join(root, version, lang), routePrefix, root, extensions, excludeRoutes, collapsed);
149
+ return walk(path.join(root, version, lang), routePrefix, root, extensions, onlyIncludeRoutes, excludeRoutes, collapsed);
150
150
  }))
151
151
  : [
152
- await walk(path.join(root, lang), addTrailingSlash(lang === defaultLang ? '' : `/${lang}`), root, extensions, excludeRoutes, collapsed),
152
+ await walk(path.join(root, lang), addTrailingSlash(lang === defaultLang ? '' : `/${lang}`), root, extensions, onlyIncludeRoutes, excludeRoutes, collapsed),
153
153
  ];
154
154
  return combineWalkResult(walks, versions);
155
155
  }));
156
156
  }
157
157
  const defaultExtensions = ['.mdx', '.md', '.tsx', '.jsx', '.ts', '.js'];
158
158
  export const autoSidebar = async (config, { ignore, export: export_ }) => {
159
+ const onlyIncludeRoutes = (ignore && config.onlyIncludeRoutes) || [];
159
160
  const excludeRoutes = (ignore && config.internalRoutes) || [];
160
161
  const route = (config.route ??= {});
161
162
  if (export_ || excludeRoutes.length) {
@@ -177,7 +178,7 @@ export const autoSidebar = async (config, { ignore, export: export_ }) => {
177
178
  const { extensions = defaultExtensions } = route;
178
179
  const collapsed = config.sidebar?.collapsed;
179
180
  if (hasLocales) {
180
- const metaInfo = await processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, excludeRoutes, collapsed);
181
+ const metaInfo = await processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, onlyIncludeRoutes, excludeRoutes, collapsed);
181
182
  config.themeConfig.locales = config.themeConfig.locales.map((item, index) => ({
182
183
  ...item,
183
184
  ...metaInfo[index],
@@ -187,9 +188,11 @@ export const autoSidebar = async (config, { ignore, export: export_ }) => {
187
188
  const walks = versions.length
188
189
  ? await Promise.all(versions.map((version) => {
189
190
  const routePrefix = addTrailingSlash(version === defaultVersion ? '' : `/${version}`);
190
- return walk(path.join(root, version), routePrefix, config.root, extensions, excludeRoutes, collapsed);
191
+ return walk(path.join(root, version), routePrefix, config.root, extensions, onlyIncludeRoutes, excludeRoutes, collapsed);
191
192
  }))
192
- : [await walk(root, '/', root, extensions, excludeRoutes, collapsed)];
193
+ : [
194
+ await walk(root, '/', root, extensions, onlyIncludeRoutes, excludeRoutes, collapsed),
195
+ ];
193
196
  const combined = combineWalkResult(walks, versions);
194
197
  config.themeConfig = { ...config.themeConfig, ...combined };
195
198
  }
@@ -7,11 +7,11 @@ export interface DoomSidebarGroup extends Omit<SidebarGroup, 'items'> {
7
7
  items: DoomSidebar[];
8
8
  weight?: number;
9
9
  }
10
- export declare function scanSideMeta(workDir: string, rootDir: string, docsDir: string, routePrefix: string, extensions: string[], ignoredDirs: string[], excludeRoutes: string[]): Promise<{
10
+ export declare function scanSideMeta(workDir: string, rootDir: string, docsDir: string, routePrefix: string, extensions: string[], ignoredDirs: string[], onlyIncludeRoutes: string[], excludeRoutes: string[]): Promise<{
11
11
  index?: DoomSidebarItem;
12
12
  others: DoomSidebar[];
13
13
  }>;
14
- export declare function walk(workDir: string, routePrefix: string | undefined, docsDir: string, extensions: string[], excludeRoutes?: string[], collapsed?: boolean): Promise<{
14
+ export declare function walk(workDir: string, routePrefix: string | undefined, docsDir: string, extensions: string[], onlyIncludeRoutes?: string[], excludeRoutes?: string[], collapsed?: boolean): Promise<{
15
15
  nav: NavItem[];
16
16
  sidebar: {
17
17
  [routePrefix]: DoomSidebar[];
@@ -15,7 +15,7 @@ const sidebarSorter = (a, b) => {
15
15
  * 1. Split sideMeta into two parts: `index` and `others` and sort `others` by weight
16
16
  * 2. filter out `excludeRoutes`
17
17
  */
18
- const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
18
+ const processSideMeta = (sideMeta, extensions, onlyIncludeRoutes, excludeRoutes) => {
19
19
  const result = sideMeta.reduce((acc, curr) => {
20
20
  if (!curr) {
21
21
  return acc;
@@ -24,7 +24,10 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
24
24
  acc.others.push(curr);
25
25
  return acc;
26
26
  }
27
- const ignored = excludeRoutes.some((glob) => picomatch.isMatch(curr._fileKey, glob));
27
+ const included = !onlyIncludeRoutes.length ||
28
+ onlyIncludeRoutes.some((glob) => picomatch.isMatch(curr._fileKey, glob));
29
+ const excluded = !included ||
30
+ excludeRoutes.some((glob) => picomatch.isMatch(curr._fileKey, glob));
28
31
  let filePart;
29
32
  if ((filePart = curr._fileKey.split(/[\\/]/).at(-1)) &&
30
33
  extensions.some((ext) => filePart === `index${ext}`)) {
@@ -42,7 +45,7 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
42
45
  else {
43
46
  acc.index = curr;
44
47
  }
45
- if (ignored) {
48
+ if (excluded) {
46
49
  if (acc.index === curr) {
47
50
  curr.link = '';
48
51
  if (acc.others.length === 0) {
@@ -57,7 +60,7 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
57
60
  }
58
61
  }
59
62
  }
60
- else if (!ignored) {
63
+ else if (!excluded) {
61
64
  acc.others.push(curr);
62
65
  }
63
66
  return acc;
@@ -65,7 +68,7 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
65
68
  result.others.sort(sidebarSorter);
66
69
  return result;
67
70
  };
68
- export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions, ignoredDirs, excludeRoutes) {
71
+ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions, ignoredDirs, onlyIncludeRoutes, excludeRoutes) {
69
72
  if (!(await pathExists(workDir))) {
70
73
  logger.error('[plugin-auto-sidebar]', `Generate sidebar meta error: ${workDir} not exists`);
71
74
  }
@@ -161,7 +164,7 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
161
164
  }
162
165
  if (type === 'dir') {
163
166
  const subDir = path.resolve(workDir, name);
164
- const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions, ['assets'], excludeRoutes);
167
+ const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions, ['assets'], onlyIncludeRoutes, excludeRoutes);
165
168
  const realPath = await detectFilePath(subDir, extensions);
166
169
  const group = {
167
170
  text: label,
@@ -201,12 +204,12 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
201
204
  tag,
202
205
  };
203
206
  }));
204
- return processSideMeta(sidebarFromMeta, extensions, excludeRoutes);
207
+ return processSideMeta(sidebarFromMeta, extensions, onlyIncludeRoutes, excludeRoutes);
205
208
  }
206
209
  // Start walking from the doc directory, scan the `_meta.json` file in each subdirectory
207
210
  // and generate the nav and sidebar config
208
- export async function walk(workDir, routePrefix = '/', docsDir, extensions, excludeRoutes = [], collapsed) {
209
- const { index, others } = await scanSideMeta(workDir, workDir, docsDir, routePrefix, extensions, ['assets', 'public', 'shared'], excludeRoutes);
211
+ export async function walk(workDir, routePrefix = '/', docsDir, extensions, onlyIncludeRoutes = [], excludeRoutes = [], collapsed) {
212
+ const { index, others } = await scanSideMeta(workDir, workDir, docsDir, routePrefix, extensions, ['assets', 'public', 'shared'], onlyIncludeRoutes, excludeRoutes);
210
213
  const sidebars = index ? [index, ...others] : others;
211
214
  if (collapsed != null) {
212
215
  for (const sidebarItem of sidebars) {
package/lib/types.d.ts CHANGED
@@ -38,6 +38,7 @@ declare module '@rspress/shared' {
38
38
  reference?: ReferenceItem[];
39
39
  sidebar?: Omit<AutoSidebarPluginOptions, 'download' | 'excludeRoutes'>;
40
40
  releaseNotes?: ReleaseNotesOptions;
41
+ onlyIncludeRoutes?: string[];
41
42
  internalRoutes?: string[];
42
43
  translate?: TranslateOptions;
43
44
  shiki?: PluginShikiOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.23.2",
3
+ "version": "0.23.3",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "git+https://github.com/alauda/doom.git",