@alauda/doom 0.23.2 → 0.23.4

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[];
@@ -11,11 +11,17 @@ const sidebarSorter = (a, b) => {
11
11
  const bWeight = 'weight' in b && b.weight != null ? b.weight : 100;
12
12
  return aWeight - bWeight;
13
13
  };
14
+ const isExcluded = (onlyIncludeRoutes, excludeRoutes, fileKey) => {
15
+ const included = !onlyIncludeRoutes.length ||
16
+ onlyIncludeRoutes.some((glob) => picomatch.isMatch(fileKey, glob));
17
+ return (!included || excludeRoutes.some((glob) => picomatch.isMatch(fileKey, glob)));
18
+ };
14
19
  /**
15
20
  * 1. Split sideMeta into two parts: `index` and `others` and sort `others` by weight
16
- * 2. filter out `excludeRoutes`
21
+ * 2. filter only include routes if `onlyIncludeRoutes` is not empty
22
+ * 3. filter out `excludeRoutes`
17
23
  */
18
- const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
24
+ const processSideMeta = (sideMeta, extensions, onlyIncludeRoutes, excludeRoutes) => {
19
25
  const result = sideMeta.reduce((acc, curr) => {
20
26
  if (!curr) {
21
27
  return acc;
@@ -24,7 +30,7 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
24
30
  acc.others.push(curr);
25
31
  return acc;
26
32
  }
27
- const ignored = excludeRoutes.some((glob) => picomatch.isMatch(curr._fileKey, glob));
33
+ const excluded = isExcluded(onlyIncludeRoutes, excludeRoutes, curr._fileKey);
28
34
  let filePart;
29
35
  if ((filePart = curr._fileKey.split(/[\\/]/).at(-1)) &&
30
36
  extensions.some((ext) => filePart === `index${ext}`)) {
@@ -42,7 +48,7 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
42
48
  else {
43
49
  acc.index = curr;
44
50
  }
45
- if (ignored) {
51
+ if (excluded) {
46
52
  if (acc.index === curr) {
47
53
  curr.link = '';
48
54
  if (acc.others.length === 0) {
@@ -57,7 +63,7 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
57
63
  }
58
64
  }
59
65
  }
60
- else if (!ignored) {
66
+ else if (!excluded) {
61
67
  acc.others.push(curr);
62
68
  }
63
69
  return acc;
@@ -65,7 +71,7 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
65
71
  result.others.sort(sidebarSorter);
66
72
  return result;
67
73
  };
68
- export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions, ignoredDirs, excludeRoutes) {
74
+ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions, ignoredDirs, onlyIncludeRoutes, excludeRoutes) {
69
75
  if (!(await pathExists(workDir))) {
70
76
  logger.error('[plugin-auto-sidebar]', `Generate sidebar meta error: ${workDir} not exists`);
71
77
  }
@@ -161,7 +167,7 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
161
167
  }
162
168
  if (type === 'dir') {
163
169
  const subDir = path.resolve(workDir, name);
164
- const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions, ['assets'], excludeRoutes);
170
+ const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions, ['assets'], onlyIncludeRoutes, excludeRoutes);
165
171
  const realPath = await detectFilePath(subDir, extensions);
166
172
  const group = {
167
173
  text: label,
@@ -201,13 +207,15 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
201
207
  tag,
202
208
  };
203
209
  }));
204
- return processSideMeta(sidebarFromMeta, extensions, excludeRoutes);
210
+ return processSideMeta(sidebarFromMeta, extensions, onlyIncludeRoutes, excludeRoutes);
205
211
  }
206
212
  // Start walking from the doc directory, scan the `_meta.json` file in each subdirectory
207
213
  // 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);
210
- const sidebars = index ? [index, ...others] : others;
214
+ export async function walk(workDir, routePrefix = '/', docsDir, extensions, onlyIncludeRoutes = [], excludeRoutes = [], collapsed) {
215
+ const { index, others } = await scanSideMeta(workDir, workDir, docsDir, routePrefix, extensions, ['assets', 'public', 'shared'], onlyIncludeRoutes, excludeRoutes);
216
+ const isIndexExcluded = !!index?._fileKey &&
217
+ isExcluded(onlyIncludeRoutes, excludeRoutes, index._fileKey);
218
+ const sidebars = index && !isIndexExcluded ? [index, ...others] : others;
211
219
  if (collapsed != null) {
212
220
  for (const sidebarItem of sidebars) {
213
221
  if ('items' in sidebarItem && sidebarItem.items.length) {
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.4",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "git+https://github.com/alauda/doom.git",