@alauda/doom 0.2.4 → 0.2.6

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.
@@ -1,6 +1,6 @@
1
- import { type UserConfig } from '@rspress/core';
1
+ import { DoomConfig } from '../utils/types.js';
2
2
  export declare function loadConfig(root?: string, configFile?: string): Promise<{
3
- config: UserConfig;
3
+ config: DoomConfig;
4
4
  filepath?: string;
5
5
  }>;
6
6
  export declare function resolveDocRoot(cwd: string, cliRoot?: string, configRoot?: string): string;
@@ -2,19 +2,27 @@ import { nodeTypes } from '@mdx-js/mdx';
2
2
  import { addLeadingSlash, addTrailingSlash, removeLeadingSlash, } from '@rspress/core';
3
3
  import { pluginPreview } from '@rspress/plugin-preview';
4
4
  import { logger } from '@rspress/shared/logger';
5
+ import getPort from 'get-port';
5
6
  import fs from 'node:fs';
6
7
  import path from 'node:path';
7
8
  import rehypeRaw from 'rehype-raw';
8
9
  import { parse } from 'yaml';
9
- import { autoSidebarPlugin, globalPlugin, apiPlugin } from '../plugins/index.js';
10
+ import { apiPlugin, autoSidebarPlugin, globalPlugin } from '../plugins/index.js';
10
11
  import { pkgResolve } from '../utils/helpers.js';
11
12
  import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, YAML_EXTENSIONS, } from './constants.js';
12
13
  const DEFAULT_LOGO = '/logo.svg';
13
- const getCommonConfig = (config) => {
14
+ const getCommonConfig = async (config) => {
14
15
  return {
15
16
  lang: 'en',
16
17
  route: {
17
- exclude: ['shared/**/*', 'doom.config.*', '**/assets/**/*', '**/*.d.ts'],
18
+ exclude: [
19
+ 'dist/**/*',
20
+ 'public/**/*',
21
+ 'shared/**/*',
22
+ 'doom.config.*',
23
+ '**/assets/**/*',
24
+ '**/*.d.ts',
25
+ ],
18
26
  },
19
27
  markdown: {
20
28
  checkDeadLinks: true,
@@ -49,7 +57,7 @@ const getCommonConfig = (config) => {
49
57
  plugins: [
50
58
  pluginPreview({
51
59
  iframeOptions: {
52
- devPort: 7891,
60
+ devPort: await getPort({ port: 7891 }),
53
61
  },
54
62
  defaultRenderMode: 'pure',
55
63
  }),
@@ -116,7 +124,7 @@ export async function loadConfig(root, configFile) {
116
124
  }
117
125
  }
118
126
  config ??= {};
119
- const mergedConfig = mergeRsbuildConfig(getCommonConfig(config), config);
127
+ const mergedConfig = mergeRsbuildConfig(await getCommonConfig(config), config);
120
128
  const base = addLeadingSlash(mergedConfig.base || '/');
121
129
  mergedConfig.base = base;
122
130
  mergedConfig.root = resolveDocRoot(CWD, root, mergedConfig.root);
@@ -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';
@@ -28,11 +28,11 @@ const splitSideMeta = (sideMeta, extensions) => {
28
28
  result.others.sort(sidebarSorter);
29
29
  return result;
30
30
  };
31
- export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions) {
31
+ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions, ignoredDirs) {
32
32
  if (!(await fs.exists(workDir))) {
33
33
  logger.error('[plugin-auto-sidebar]', `Generate sidebar meta error: ${workDir} not exists`);
34
34
  }
35
- const addRoutePrefix = (link) => `${routePrefix}${link}`;
35
+ const addRoutePrefix = (link) => `${routePrefix}${removeLeadingSlash(link)}`;
36
36
  // find the `_meta.json` file
37
37
  const metaFile = path.resolve(workDir, '_meta.json');
38
38
  // Fix the windows path
@@ -58,12 +58,15 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
58
58
  });
59
59
  sideMeta = (await Promise.all(subItems.map(async (item) => {
60
60
  // Fix https://github.com/web-infra-dev/rspress/issues/346
61
- if (item === '_meta.json' || item === 'assets') {
61
+ if (item === '_meta.json') {
62
62
  return null;
63
63
  }
64
64
  const stat = await fs.stat(path.join(workDir, item));
65
65
  // If the item is a directory, we will transform it to a object with `type` and `name` property.
66
66
  if (stat.isDirectory()) {
67
+ if (ignoredDirs.includes(item)) {
68
+ return null;
69
+ }
67
70
  // set H1 title to sidebar label when have same name md/mdx file
68
71
  const mdFilePath = path.join(workDir, `${item}.md`);
69
72
  const mdxFilePath = path.join(workDir, `${item}.mdx`);
@@ -121,7 +124,7 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
121
124
  }
122
125
  if (type === 'dir') {
123
126
  const subDir = path.resolve(workDir, name);
124
- const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions);
127
+ const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions, ['assets']);
125
128
  const realPath = await detectFilePath(subDir, extensions);
126
129
  const group = {
127
130
  text: label,
@@ -180,27 +183,13 @@ export async function walk(workDir, routePrefix = '/', docsDir, extensions) {
180
183
  navItem.link = withBase(navItem.link, routePrefix);
181
184
  }
182
185
  });
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 = [];
186
+ const { index, others } = await scanSideMeta(workDir, workDir, docsDir, routePrefix, extensions, ['assets', 'public', 'shared']);
187
+ const sidebars = index ? [index, ...others] : others;
188
+ sidebars.sort(sidebarSorter);
188
189
  // Every sub dir will represent a group of sidebar
189
190
  const sidebarConfig = {
190
191
  [routePrefix]: sidebars,
191
192
  };
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
193
  if (removeTrailingSlash(routePrefix)) {
205
194
  sidebarConfig[removeTrailingSlash(routePrefix)] = sidebars;
206
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -44,6 +44,7 @@
44
44
  "clsx": "^2.1.1",
45
45
  "commander": "^12.1.0",
46
46
  "es-toolkit": "^1.29.0",
47
+ "get-port": "^7.1.0",
47
48
  "react-markdown": "^8.0.7",
48
49
  "rehype-raw": "^6.1.1",
49
50
  "remark-gfm": "^3.0.1",