@alauda/doom 0.20.7 → 0.21.0
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/export.js +1 -2
- package/lib/cli/load-config.js +3 -1
- package/lib/global/VersionsNav/index.js +0 -1
- package/lib/plugins/auto-toc/index.d.ts +2 -0
- package/lib/plugins/auto-toc/index.js +9 -0
- package/lib/plugins/auto-toc/remark-auto-toc.d.ts +3 -0
- package/lib/plugins/auto-toc/remark-auto-toc.js +79 -0
- package/lib/plugins/replace/parse-toc.js +1 -4
- package/lib/plugins/replace/rehype-normalize-link.js +1 -1
- package/lib/plugins/replace/utils.d.ts +0 -2
- package/lib/plugins/replace/utils.js +0 -28
- package/lib/plugins/shared.d.ts +2 -0
- package/lib/plugins/shared.js +45 -0
- package/lib/runtime/hooks/useTranslation.d.ts +1 -1
- package/lib/runtime/translation.d.ts +4 -0
- package/lib/runtime/translation.js +3 -0
- package/package.json +1 -1
- package/styles/global.scss +6 -0
package/lib/cli/export.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { tmpdir } from 'node:os';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import { removeLeadingSlash, serve } from '@rspress/core';
|
|
4
3
|
import { logger } from '@rspress/shared/logger';
|
|
@@ -52,7 +51,7 @@ export const exportCommand = new Command('export')
|
|
|
52
51
|
return pages;
|
|
53
52
|
};
|
|
54
53
|
const commonOptions = {
|
|
55
|
-
tempDir:
|
|
54
|
+
tempDir: path.resolve(outDir, '.doom'),
|
|
56
55
|
port: port,
|
|
57
56
|
host: host || 'localhost',
|
|
58
57
|
outDir,
|
package/lib/cli/load-config.js
CHANGED
|
@@ -7,6 +7,7 @@ import { logger } from '@rspress/shared/logger';
|
|
|
7
7
|
import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
|
|
8
8
|
import { difference } from 'es-toolkit';
|
|
9
9
|
import rehypeRaw from 'rehype-raw';
|
|
10
|
+
import { autoTocPlugin } from '../plugins/auto-toc/index.js';
|
|
10
11
|
import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, replacePlugin, shikiPlugin, } from '../plugins/index.js';
|
|
11
12
|
import { isExplicitlyUnversioned, UNVERSIONED, } from '../shared/index.js';
|
|
12
13
|
import { pathExists, pkgResolve, resolveStaticConfig } from '../utils/index.js';
|
|
@@ -108,6 +109,7 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
|
|
|
108
109
|
localBasePath,
|
|
109
110
|
}),
|
|
110
111
|
autoSidebarPlugin({ export: export_, ignore }),
|
|
112
|
+
autoTocPlugin(),
|
|
111
113
|
directivesPlugin(),
|
|
112
114
|
globalPlugin({ version, download }),
|
|
113
115
|
mermaidPlugin(),
|
|
@@ -277,7 +279,7 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
|
|
|
277
279
|
}
|
|
278
280
|
outDir ||= mergedConfig.outDir;
|
|
279
281
|
mergedConfig.outDir = `dist${(outDir ? addLeadingSlash(addTrailingSlash(outDir)) : base) +
|
|
280
|
-
(isExplicitlyUnversioned(version) ? UNVERSIONED : version)}`;
|
|
282
|
+
(isExplicitlyUnversioned(version) ? UNVERSIONED : outDir ? version : '')}`;
|
|
281
283
|
if (mergedConfig.builderConfig?.server?.open === true) {
|
|
282
284
|
mergedConfig.builderConfig.server.open = mergedConfig.base;
|
|
283
285
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getASTNodeImport } from '../shared.js';
|
|
2
|
+
export const remarkAutoToc = function () {
|
|
3
|
+
return (root) => {
|
|
4
|
+
let foundIndex = -1;
|
|
5
|
+
for (const [index, node] of root.children.entries()) {
|
|
6
|
+
if (node.type === 'heading' && node.depth === 2) {
|
|
7
|
+
foundIndex = index;
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
if (foundIndex === -1) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
root.children.splice(foundIndex, 0, getASTNodeImport({ useTranslation: 'useTranslation_' }, '@alauda/doom/runtime'), {
|
|
15
|
+
type: 'mdxJsxFlowElement',
|
|
16
|
+
name: 'div',
|
|
17
|
+
attributes: [
|
|
18
|
+
{
|
|
19
|
+
type: 'mdxJsxAttribute',
|
|
20
|
+
name: 'className',
|
|
21
|
+
value: 'doom-auto-toc',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
children: [
|
|
25
|
+
{
|
|
26
|
+
type: 'heading',
|
|
27
|
+
depth: 2,
|
|
28
|
+
children: [
|
|
29
|
+
{
|
|
30
|
+
type: 'mdxTextExpression',
|
|
31
|
+
value: "useTranslation_()('toc')",
|
|
32
|
+
data: {
|
|
33
|
+
estree: {
|
|
34
|
+
type: 'Program',
|
|
35
|
+
sourceType: 'module',
|
|
36
|
+
body: [
|
|
37
|
+
{
|
|
38
|
+
type: 'ExpressionStatement',
|
|
39
|
+
expression: {
|
|
40
|
+
type: 'CallExpression',
|
|
41
|
+
callee: {
|
|
42
|
+
type: 'CallExpression',
|
|
43
|
+
callee: {
|
|
44
|
+
type: 'Identifier',
|
|
45
|
+
name: 'useTranslation_',
|
|
46
|
+
},
|
|
47
|
+
arguments: [],
|
|
48
|
+
optional: false,
|
|
49
|
+
},
|
|
50
|
+
arguments: [
|
|
51
|
+
{
|
|
52
|
+
type: 'Literal',
|
|
53
|
+
value: 'toc',
|
|
54
|
+
raw: "'toc'",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
optional: false,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'text',
|
|
66
|
+
value: ' {#toc}',
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: 'mdxJsxFlowElement',
|
|
72
|
+
name: 'Toc',
|
|
73
|
+
attributes: [],
|
|
74
|
+
children: [],
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isExternalUrl } from '@rspress/core';
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
|
-
import { getASTNodeImport } from '
|
|
3
|
+
import { getASTNodeImport } from '../shared.js';
|
|
4
4
|
const getMdxSrcAttribute = (tempVar) => {
|
|
5
5
|
return {
|
|
6
6
|
type: 'mdxJsxAttribute',
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Root, YAML } from 'mdast';
|
|
2
|
-
import type { MdxjsEsm } from 'mdast-util-mdxjs-esm';
|
|
3
2
|
import { type Options } from 'remark-stringify';
|
|
4
3
|
import type { NormalizedReferenceSource, ReferenceItem } from './types.js';
|
|
5
4
|
export declare const RELATIVE_URL_PATTERN: RegExp;
|
|
@@ -8,7 +7,6 @@ export declare const RELATIVE_URL_PATTERN: RegExp;
|
|
|
8
7
|
*/
|
|
9
8
|
export declare const extractTextAndId: (title: string) => string[];
|
|
10
9
|
export declare const normalizeReferenceItems: (items?: ReferenceItem[]) => Record<string, NormalizedReferenceSource>;
|
|
11
|
-
export declare const getASTNodeImport: (name: string, from: string) => MdxjsEsm;
|
|
12
10
|
export declare const stringifySettings: Options;
|
|
13
11
|
export declare const mdProcessor: import("unified").FrozenProcessor<Root, Root, Root, string>;
|
|
14
12
|
export declare const mdxProcessor: import("unified").FrozenProcessor<Root, Root, Root, string>;
|
|
@@ -34,34 +34,6 @@ export const normalizeReferenceItems = (items = []) => items.reduce((acc, curr)
|
|
|
34
34
|
}
|
|
35
35
|
return acc;
|
|
36
36
|
}, {});
|
|
37
|
-
// Construct import statement for AST
|
|
38
|
-
// Such as: import image1 from './test.png'
|
|
39
|
-
export const getASTNodeImport = (name, from) => ({
|
|
40
|
-
type: 'mdxjsEsm',
|
|
41
|
-
value: `import ${name} from ${JSON.stringify(from)}`,
|
|
42
|
-
data: {
|
|
43
|
-
estree: {
|
|
44
|
-
type: 'Program',
|
|
45
|
-
sourceType: 'module',
|
|
46
|
-
body: [
|
|
47
|
-
{
|
|
48
|
-
type: 'ImportDeclaration',
|
|
49
|
-
specifiers: [
|
|
50
|
-
{
|
|
51
|
-
type: 'ImportDefaultSpecifier',
|
|
52
|
-
local: { type: 'Identifier', name },
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
source: {
|
|
56
|
-
type: 'Literal',
|
|
57
|
-
value: from,
|
|
58
|
-
raw: JSON.stringify(from),
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
37
|
export const stringifySettings = {
|
|
66
38
|
bullet: '-',
|
|
67
39
|
listItemIndent: 'one',
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Construct import statement for AST
|
|
2
|
+
// Such as: import image1 from './test.png'
|
|
3
|
+
export function getASTNodeImport(name, from) {
|
|
4
|
+
const isStringName = typeof name === 'string';
|
|
5
|
+
return {
|
|
6
|
+
type: 'mdxjsEsm',
|
|
7
|
+
value: `import ${isStringName
|
|
8
|
+
? name
|
|
9
|
+
: `{${Object.entries(name)
|
|
10
|
+
.map(([imported, local]) => `${imported}${imported === local || !local ? '' : ` as ${local}`}`)
|
|
11
|
+
.join(',')}}`} from ${JSON.stringify(from)}`,
|
|
12
|
+
data: {
|
|
13
|
+
estree: {
|
|
14
|
+
type: 'Program',
|
|
15
|
+
sourceType: 'module',
|
|
16
|
+
body: [
|
|
17
|
+
{
|
|
18
|
+
type: 'ImportDeclaration',
|
|
19
|
+
specifiers: isStringName
|
|
20
|
+
? [
|
|
21
|
+
{
|
|
22
|
+
type: 'ImportDefaultSpecifier',
|
|
23
|
+
local: { type: 'Identifier', name },
|
|
24
|
+
},
|
|
25
|
+
]
|
|
26
|
+
: Object.entries(name).map(([imported, local]) => ({
|
|
27
|
+
type: 'ImportSpecifier',
|
|
28
|
+
imported: { type: 'Identifier', name: imported },
|
|
29
|
+
local: {
|
|
30
|
+
type: 'Identifier',
|
|
31
|
+
name: local || imported,
|
|
32
|
+
},
|
|
33
|
+
})),
|
|
34
|
+
source: {
|
|
35
|
+
type: 'Literal',
|
|
36
|
+
value: from,
|
|
37
|
+
raw: JSON.stringify(from),
|
|
38
|
+
},
|
|
39
|
+
attributes: [],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Language } from '../../shared/index.js';
|
|
2
2
|
export declare const useLang: () => Language;
|
|
3
|
-
export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "create" | "update" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf") => string;
|
|
3
|
+
export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "create" | "update" | "toc" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf") => string;
|
|
@@ -15,6 +15,7 @@ declare const en: {
|
|
|
15
15
|
chinese_bad_cases: string;
|
|
16
16
|
english_bad_cases: string;
|
|
17
17
|
download_pdf: string;
|
|
18
|
+
toc: string;
|
|
18
19
|
};
|
|
19
20
|
export type Translation = typeof en;
|
|
20
21
|
export declare const TRANSLATIONS: {
|
|
@@ -35,6 +36,7 @@ export declare const TRANSLATIONS: {
|
|
|
35
36
|
chinese_bad_cases: string;
|
|
36
37
|
english_bad_cases: string;
|
|
37
38
|
download_pdf: string;
|
|
39
|
+
toc: string;
|
|
38
40
|
};
|
|
39
41
|
zh: {
|
|
40
42
|
collapse_all: string;
|
|
@@ -53,6 +55,7 @@ export declare const TRANSLATIONS: {
|
|
|
53
55
|
chinese_bad_cases: string;
|
|
54
56
|
english_bad_cases: string;
|
|
55
57
|
download_pdf: string;
|
|
58
|
+
toc: string;
|
|
56
59
|
};
|
|
57
60
|
ru: {
|
|
58
61
|
collapse_all: string;
|
|
@@ -71,6 +74,7 @@ export declare const TRANSLATIONS: {
|
|
|
71
74
|
chinese_bad_cases: string;
|
|
72
75
|
english_bad_cases: string;
|
|
73
76
|
download_pdf: string;
|
|
77
|
+
toc: string;
|
|
74
78
|
};
|
|
75
79
|
};
|
|
76
80
|
export {};
|
|
@@ -15,6 +15,7 @@ const en = {
|
|
|
15
15
|
chinese_bad_cases: 'Chinese Bad Cases',
|
|
16
16
|
english_bad_cases: 'English Bad Cases',
|
|
17
17
|
download_pdf: 'Download PDF',
|
|
18
|
+
toc: 'TOC',
|
|
18
19
|
};
|
|
19
20
|
const zh = {
|
|
20
21
|
collapse_all: '全部收起',
|
|
@@ -33,6 +34,7 @@ const zh = {
|
|
|
33
34
|
chinese_bad_cases: '中文反例',
|
|
34
35
|
english_bad_cases: '英文反例',
|
|
35
36
|
download_pdf: '下载 PDF',
|
|
37
|
+
toc: '目录',
|
|
36
38
|
};
|
|
37
39
|
const ru = {
|
|
38
40
|
collapse_all: 'Свернуть всё',
|
|
@@ -51,5 +53,6 @@ const ru = {
|
|
|
51
53
|
chinese_bad_cases: 'Примеры ошибок на китайском',
|
|
52
54
|
english_bad_cases: 'Примеры ошибок на английском',
|
|
53
55
|
download_pdf: 'Скачать PDF',
|
|
56
|
+
toc: 'Содержание',
|
|
54
57
|
};
|
|
55
58
|
export const TRANSLATIONS = { en, zh, ru };
|
package/package.json
CHANGED
package/styles/global.scss
CHANGED
|
@@ -107,6 +107,12 @@ td {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
.doom-auto-toc {
|
|
111
|
+
@media (min-width: 1280px) {
|
|
112
|
+
display: none;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
110
116
|
.dark .doom-tabs .language-mdx {
|
|
111
117
|
// https://github.com/web-infra-dev/rspress/blob/bbe6476c8394f9c95a98fd791f0614481f89d878/packages/theme-default/src/styles/code.css#L17
|
|
112
118
|
--rp-code-block-bg: #{color.adjust($color: #242424, $lightness: 5%)};
|