@alauda/doom 0.2.5 → 0.2.7

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.
@@ -15,7 +15,14 @@ const getCommonConfig = async (config) => {
15
15
  return {
16
16
  lang: 'en',
17
17
  route: {
18
- exclude: ['shared/**/*', 'doom.config.*', '**/assets/**/*', '**/*.d.ts'],
18
+ exclude: [
19
+ 'dist/**/*',
20
+ 'public/**/*',
21
+ 'shared/**/*',
22
+ 'doom.config.*',
23
+ '**/assets/**/*',
24
+ '**/*.d.ts',
25
+ ],
19
26
  },
20
27
  markdown: {
21
28
  checkDeadLinks: true,
@@ -33,10 +33,15 @@ export async function extractInfoFromFrontmatter(filePath, rootDir, extensions)
33
33
  const fileNameWithoutExt = path.basename(realPath, path.extname(realPath));
34
34
  const h1RegExp = /^#\s+(.*)$/m;
35
35
  const match = content.match(h1RegExp);
36
+ let contentTitle = match?.[1];
37
+ if (contentTitle) {
38
+ contentTitle =
39
+ contentTitle.match(/{\s*useI18n\s*\(\s*\)\s*\(\s*(['"])([^'"]+)\1\s*\)\s*}/m)?.[2] ?? contentTitle;
40
+ }
36
41
  const { frontmatter } = loadFrontMatter(content, filePath, rootDir);
37
42
  return {
38
43
  realPath,
39
- title: frontmatter.title || match?.[1] || fileNameWithoutExt,
44
+ title: frontmatter.title || contentTitle || fileNameWithoutExt,
40
45
  overviewHeaders: frontmatter.overviewHeaders,
41
46
  context: frontmatter.context,
42
47
  weight: frontmatter.weight,
@@ -7,7 +7,7 @@ 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[]): Promise<{
10
+ export declare function scanSideMeta(workDir: string, rootDir: string, docsDir: string, routePrefix: string, extensions: string[], ignoredDirs: string[]): Promise<{
11
11
  index?: DoomSidebarItem;
12
12
  others: DoomSidebar[];
13
13
  }>;
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, removeTrailingSlash, slash, withBase, } from '@rspress/shared';
1
+ import { isExternalUrl, removeLeadingSlash, removeTrailingSlash, slash, withBase, } from '@rspress/shared';
2
2
  import fs from '@rspress/shared/fs-extra';
3
3
  import { logger } from '@rspress/shared/logger';
4
4
  import path from 'node:path';
@@ -14,10 +14,12 @@ const sidebarSorter = (a, b) => {
14
14
  */
15
15
  const splitSideMeta = (sideMeta, extensions) => {
16
16
  const result = sideMeta.reduce((acc, curr) => {
17
+ let fileParts;
17
18
  if ('_fileKey' in curr &&
18
19
  !('items' in curr) &&
19
20
  !acc.index &&
20
- extensions.some((ext) => curr._fileKey?.endsWith(`/index${ext}`))) {
21
+ (fileParts = curr._fileKey?.split('/')) &&
22
+ extensions.some((ext) => fileParts.at(-1) === `index${ext}`)) {
21
23
  acc.index = curr;
22
24
  }
23
25
  else {
@@ -28,11 +30,11 @@ const splitSideMeta = (sideMeta, extensions) => {
28
30
  result.others.sort(sidebarSorter);
29
31
  return result;
30
32
  };
31
- export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions) {
33
+ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions, ignoredDirs) {
32
34
  if (!(await fs.exists(workDir))) {
33
35
  logger.error('[plugin-auto-sidebar]', `Generate sidebar meta error: ${workDir} not exists`);
34
36
  }
35
- const addRoutePrefix = (link) => `${routePrefix}${link}`;
37
+ const addRoutePrefix = (link) => `${routePrefix}${removeLeadingSlash(link)}`;
36
38
  // find the `_meta.json` file
37
39
  const metaFile = path.resolve(workDir, '_meta.json');
38
40
  // Fix the windows path
@@ -58,12 +60,15 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
58
60
  });
59
61
  sideMeta = (await Promise.all(subItems.map(async (item) => {
60
62
  // Fix https://github.com/web-infra-dev/rspress/issues/346
61
- if (item === '_meta.json' || item === 'assets') {
63
+ if (item === '_meta.json') {
62
64
  return null;
63
65
  }
64
66
  const stat = await fs.stat(path.join(workDir, item));
65
67
  // If the item is a directory, we will transform it to a object with `type` and `name` property.
66
68
  if (stat.isDirectory()) {
69
+ if (ignoredDirs.includes(item)) {
70
+ return null;
71
+ }
67
72
  // set H1 title to sidebar label when have same name md/mdx file
68
73
  const mdFilePath = path.join(workDir, `${item}.md`);
69
74
  const mdxFilePath = path.join(workDir, `${item}.mdx`);
@@ -121,7 +126,7 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
121
126
  }
122
127
  if (type === 'dir') {
123
128
  const subDir = path.resolve(workDir, name);
124
- const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions);
129
+ const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions, ['assets']);
125
130
  const realPath = await detectFilePath(subDir, extensions);
126
131
  const group = {
127
132
  text: label,
@@ -180,27 +185,12 @@ export async function walk(workDir, routePrefix = '/', docsDir, extensions) {
180
185
  navItem.link = withBase(navItem.link, routePrefix);
181
186
  }
182
187
  });
183
- // find the `_meta.json` file in the subdirectory
184
- const subDirs = (await fs.readdir(workDir)).filter((v) => fs.statSync(path.join(workDir, v)).isDirectory() &&
185
- v !== 'node_modules' &&
186
- (workDir !== docsDir || !['public', 'shared'].includes(v)));
187
- const sidebars = [];
188
+ const { index, others } = await scanSideMeta(workDir, workDir, docsDir, routePrefix, extensions, ['assets', 'public', 'shared']);
189
+ const sidebars = index ? [index, ...others] : others;
188
190
  // Every sub dir will represent a group of sidebar
189
191
  const sidebarConfig = {
190
192
  [routePrefix]: sidebars,
191
193
  };
192
- for (const subDir of subDirs) {
193
- const { index, others } = await scanSideMeta(path.join(workDir, subDir), workDir, docsDir, routePrefix, extensions);
194
- const sidebar = index
195
- ? { ...index, items: others }
196
- : { text: subDir, items: others };
197
- if (!sidebar.items.length) {
198
- // @ts-expect-error -- FIXME: rspress should handle `undefined` items
199
- delete sidebar.items;
200
- }
201
- sidebars.push(sidebar);
202
- }
203
- sidebars.sort(sidebarSorter);
204
194
  if (removeTrailingSlash(routePrefix)) {
205
195
  sidebarConfig[removeTrailingSlash(routePrefix)] = sidebars;
206
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {