@alauda/doom 0.2.5 → 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.
package/lib/cli/load-config.js
CHANGED
|
@@ -15,7 +15,14 @@ const getCommonConfig = async (config) => {
|
|
|
15
15
|
return {
|
|
16
16
|
lang: 'en',
|
|
17
17
|
route: {
|
|
18
|
-
exclude: [
|
|
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 ||
|
|
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'
|
|
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
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
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
|
}
|