@alauda/doom 0.11.7 → 0.12.1
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.d.ts +4 -0
- package/lib/cli/export.js +33 -0
- package/lib/cli/index.js +3 -0
- package/lib/cli/load-config.d.ts +1 -1
- package/lib/cli/load-config.js +4 -3
- package/lib/cli/new.d.ts +1 -1
- package/lib/cli/translate.d.ts +14 -0
- package/lib/cli/translate.js +154 -0
- package/lib/config.d.ts +1 -1
- package/lib/plugins/api/types.js +1 -1
- package/lib/plugins/auto-sidebar/index.js +0 -5
- package/lib/plugins/auto-sidebar/utils.d.ts +1 -1
- package/lib/plugins/permission/index.d.ts +1 -1
- package/lib/plugins/permission/index.js +1 -1
- package/lib/plugins/permission/types.d.ts +1 -1
- package/lib/plugins/replace/normalize-img-src.d.ts +4 -3
- package/lib/plugins/replace/normalize-img-src.js +11 -5
- package/lib/plugins/replace/types.d.ts +1 -1
- package/lib/plugins/replace/utils.js +1 -1
- package/lib/runtime/components/Callouts.d.ts +1 -1
- package/lib/runtime/components/Directive.d.ts +1 -1
- package/lib/runtime/components/ExternalApisOverview.d.ts +1 -1
- package/lib/runtime/components/ExternalSite.d.ts +1 -1
- package/lib/runtime/components/ExternalSiteLink.d.ts +1 -1
- package/lib/runtime/components/K8sCrd.d.ts +1 -1
- package/lib/runtime/components/OpenAPIRef.d.ts +1 -1
- package/lib/runtime/components/_ExternalSiteBase.d.ts +1 -1
- package/lib/runtime/components/_HeadingTitle.js +1 -0
- package/lib/runtime/hooks/useSiteOverrides.d.ts +1 -1
- package/lib/runtime/hooks/useTranslation.js +1 -1
- package/lib/utils/fs.d.ts +1 -1
- package/lib/utils/fs.js +8 -2
- package/lib/utils/helpers.d.ts +1 -1
- package/lib/utils/helpers.js +2 -2
- package/lib/utils/types.d.ts +1 -1
- package/package.json +6 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { serve } from '@rspress/core';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { chromium } from 'playwright';
|
|
4
|
+
import { autoSidebar } from '../plugins/auto-sidebar/index.js';
|
|
5
|
+
import { loadConfig } from './load-config.js';
|
|
6
|
+
export const processExport = async (sidebar, lang) => {
|
|
7
|
+
console.log(sidebar, lang);
|
|
8
|
+
chromium.launch({
|
|
9
|
+
headless: false,
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export const exportCommand = new Command('export')
|
|
13
|
+
.description('Export the documentation to docx/pdf format')
|
|
14
|
+
.argument('[root]', 'Root directory of the documentation')
|
|
15
|
+
.option('--host [host]', 'Host name')
|
|
16
|
+
.option('--port [port]', 'Port number', '4173')
|
|
17
|
+
.action(async function (root) {
|
|
18
|
+
const { port, host, ...globalOptions } = this.optsWithGlobals();
|
|
19
|
+
const { config } = await loadConfig(root, globalOptions);
|
|
20
|
+
const { hasLocales } = await autoSidebar({
|
|
21
|
+
...config.sidebar,
|
|
22
|
+
excludeRoutes: (globalOptions.ignore && config.internalRoutes) || [],
|
|
23
|
+
}, config);
|
|
24
|
+
await serve({ config, host, port });
|
|
25
|
+
if (hasLocales) {
|
|
26
|
+
for (const { lang, sidebar } of config.themeConfig.locales) {
|
|
27
|
+
await processExport(sidebar, lang);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
await processExport(config.themeConfig.sidebar, config.lang);
|
|
32
|
+
}
|
|
33
|
+
});
|
package/lib/cli/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { green } from 'yoctocolors';
|
|
|
12
12
|
import { CWD, DEFAULT_CONFIGS, I18N_FILE, SITES_FILE } from './constants.js';
|
|
13
13
|
import { loadConfig } from './load-config.js';
|
|
14
14
|
import { newCommand } from './new.js';
|
|
15
|
+
import { translateCommand } from './translate.js';
|
|
15
16
|
const META_FILE = '_meta.json';
|
|
16
17
|
const CONFIG_FILES = [...DEFAULT_CONFIGS, I18N_FILE, SITES_FILE];
|
|
17
18
|
const setNodeEnv = (env) => {
|
|
@@ -136,9 +137,11 @@ program
|
|
|
136
137
|
});
|
|
137
138
|
});
|
|
138
139
|
program.addCommand(newCommand);
|
|
140
|
+
program.addCommand(translateCommand);
|
|
139
141
|
program.parseAsync().catch((err) => {
|
|
140
142
|
if (err instanceof Error && err.name === 'ExitPromptError') {
|
|
141
143
|
return;
|
|
142
144
|
}
|
|
143
145
|
logger.error(err);
|
|
146
|
+
process.exit(1);
|
|
144
147
|
});
|
package/lib/cli/load-config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DoomConfig, GlobalCliOptions } from '../utils/index.js';
|
|
1
|
+
import { type DoomConfig, type GlobalCliOptions } from '../utils/index.js';
|
|
2
2
|
export declare function loadConfig(root?: string, { config: configFile, prefix, v: version, ignore, force, }?: GlobalCliOptions): Promise<{
|
|
3
3
|
config: DoomConfig;
|
|
4
4
|
filepath?: string;
|
package/lib/cli/load-config.js
CHANGED
|
@@ -6,12 +6,12 @@ import { logger } from '@rspress/shared/logger';
|
|
|
6
6
|
import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
|
|
7
7
|
import rehypeRaw from 'rehype-raw';
|
|
8
8
|
import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, shikiPlugin, } from '../plugins/index.js';
|
|
9
|
+
import { mermaidPlugin } from '../plugins/mermaid/index.js';
|
|
10
|
+
import { permissionPlugin } from '../plugins/permission/index.js';
|
|
11
|
+
import { replacePlugin } from '../plugins/replace/index.js';
|
|
9
12
|
import { normalizeVersion } from '../shared/index.js';
|
|
10
13
|
import { pkgResolve, resolveStaticConfig, } from '../utils/index.js';
|
|
11
14
|
import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
|
|
12
|
-
import { replacePlugin } from '../plugins/replace/index.js';
|
|
13
|
-
import { mermaidPlugin } from '../plugins/mermaid/index.js';
|
|
14
|
-
import { permissionPlugin } from '../plugins/permission/index.js';
|
|
15
15
|
const DEFAULT_LOGO = '/logo.svg';
|
|
16
16
|
const zhLocaleConfig = {
|
|
17
17
|
searchPlaceholderText: '搜索文档',
|
|
@@ -176,6 +176,7 @@ export async function loadConfig(root, { config: configFile, prefix, v: version,
|
|
|
176
176
|
const normalizedVersion = normalizeVersion(version);
|
|
177
177
|
const commonConfig = getCommonConfig(config, root, configFilePath, normalizedVersion, ignore, force);
|
|
178
178
|
const mergedConfig = mergeRsbuildConfig(commonConfig, config, {
|
|
179
|
+
lang: commonConfig.lang,
|
|
179
180
|
root: commonConfig.root,
|
|
180
181
|
});
|
|
181
182
|
let base = addLeadingSlash(mergedConfig.base || '/');
|
package/lib/cli/new.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as prompts from '@inquirer/prompts';
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
-
import { ContentProcessor } from '../utils/types.js';
|
|
3
|
+
import type { ContentProcessor } from '../utils/types.js';
|
|
4
4
|
export declare const DEFAULT_PATH = "templates/scaffolding.yaml";
|
|
5
5
|
export interface ScaffoldingTemplate {
|
|
6
6
|
repo: string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export interface I18nFrontmatter {
|
|
3
|
+
i18n?: {
|
|
4
|
+
title?: {
|
|
5
|
+
en?: string;
|
|
6
|
+
};
|
|
7
|
+
additionalPrompts?: string;
|
|
8
|
+
disableAutoTranslation?: boolean;
|
|
9
|
+
};
|
|
10
|
+
sourceSHA?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const translate: (zhContent: string, enContent?: string, additionalPrompts?: string) => Promise<string>;
|
|
14
|
+
export declare const translateCommand: Command;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { logger } from '@rspress/shared/logger';
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
import matter from 'gray-matter';
|
|
7
|
+
import { AzureOpenAI } from 'openai';
|
|
8
|
+
import { pRateLimit } from 'p-ratelimit';
|
|
9
|
+
import { cyan } from 'yoctocolors';
|
|
10
|
+
import { pathExists } from '../utils/index.js';
|
|
11
|
+
import { loadConfig } from './load-config.js';
|
|
12
|
+
import { mdProcessor, mdxProcessor } from '../plugins/replace/utils.js';
|
|
13
|
+
import { normalizeImgSrc } from '../plugins/replace/normalize-img-src.js';
|
|
14
|
+
let openai;
|
|
15
|
+
export const translate = async (zhContent, enContent = '', additionalPrompts = '') => {
|
|
16
|
+
if (!openai) {
|
|
17
|
+
openai = new AzureOpenAI({
|
|
18
|
+
endpoint: process.env.AZURE_OPENAI_ENDPOINT ||
|
|
19
|
+
'https://apt-docs-openai.openai.azure.com',
|
|
20
|
+
apiKey: process.env.AZURE_OPENAI_API_KEY || 'doom',
|
|
21
|
+
apiVersion: process.env.OPENAI_API_VERSION || '2025-01-01-preview',
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const { choices } = await openai.beta.chat.completions.parse({
|
|
25
|
+
messages: [
|
|
26
|
+
{
|
|
27
|
+
role: 'system',
|
|
28
|
+
content: `
|
|
29
|
+
## 角色
|
|
30
|
+
你是一位专业的技术文档工程师,擅长写作高质量的英文技术分档。请你帮我准确地将以下中文翻译成英文,风格与英文技术文档保持一致。
|
|
31
|
+
|
|
32
|
+
## 规则
|
|
33
|
+
- 第一条消息为需要翻译的最新中文内容,第二条消息为之前翻译过的但内容可能过期的英文内容,如果没有翻译过则为空
|
|
34
|
+
- 输入格式为 MDX 格式,输出格式也必须保留原始 MDX 格式,且不要额外包装在不必要的代码块中
|
|
35
|
+
- 文档中的资源链接不要翻译和替换
|
|
36
|
+
- MDX 组件中包含的内容需要翻译,MDX 组件参数的值不需要翻译,但以下这些特殊的 MDX 组件参数值需要翻译
|
|
37
|
+
* 组件示例: <Tab label="参数值">组件包含的内容</Tab>,label 是 key 不用翻译,"参数值" 需要翻译
|
|
38
|
+
- 以下是常见的相关术语词汇对应表(中文 -> English)
|
|
39
|
+
* ACP -> ACP
|
|
40
|
+
* 灵雀云 -> Alauda
|
|
41
|
+
- 移除 {/* reference-start */}, {/* reference-end */}, <!-- reference-start --> 和 <!-- reference-end --> 相关的注释
|
|
42
|
+
- 翻译过程中务必保留原文中的 \\< 转义字符不要做任何转义变更
|
|
43
|
+
|
|
44
|
+
## 策略
|
|
45
|
+
分四步进行翻译工作,并打印每步的结果:
|
|
46
|
+
1. 根据中文内容直译成英文,保持原有格式,不要遗漏任何信息
|
|
47
|
+
2. 根据第一步直译的结果,指出其中存在的具体问题,要准确描述,不宜笼统的表示,也不需要增加原文不存在的内容或格式,包括不仅限于
|
|
48
|
+
- 不符合英文表达习惯,明确指出不符合的地方
|
|
49
|
+
- 语句不通顺,指出位置,不需要给出修改意见,意译时修复
|
|
50
|
+
- 晦涩难懂,模棱两可,不易理解,可以尝试给出解释
|
|
51
|
+
3. 根据第一步直译的结果和第二步指出的问题,重新进行意译,保证内容的原意的基础上,使其更易于理解,更符合英文技术文档的表达习惯,同时保持原有的格式不变
|
|
52
|
+
4. 当存在之前翻译的英文内容时,将第三步的结果按句子与之前的英文内容细致地比较,如果翻译结果意思相近,仅仅表达方式不同的,只需要保留之前的英文内容即可,不需要重复翻译
|
|
53
|
+
|
|
54
|
+
最终只需要输出最后一步的结果,不需要输出之前步骤的结果。
|
|
55
|
+
|
|
56
|
+
${additionalPrompts}
|
|
57
|
+
`.trim(),
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
role: 'user',
|
|
61
|
+
content: zhContent,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
role: 'user',
|
|
65
|
+
content: enContent,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
model: 'gpt-4o-mini',
|
|
69
|
+
});
|
|
70
|
+
const { content, refusal } = choices[0].message;
|
|
71
|
+
if (refusal) {
|
|
72
|
+
throw new Error(refusal);
|
|
73
|
+
}
|
|
74
|
+
return content;
|
|
75
|
+
};
|
|
76
|
+
const limit = pRateLimit({
|
|
77
|
+
interval: 60_000, // 1min
|
|
78
|
+
rate: 50,
|
|
79
|
+
concurrency: 10,
|
|
80
|
+
});
|
|
81
|
+
export const translateCommand = new Command('translate')
|
|
82
|
+
.description('Translate the documentation')
|
|
83
|
+
.argument('[root]', 'Root directory of the documentation')
|
|
84
|
+
.action(async function (root) {
|
|
85
|
+
const { config } = await loadConfig(root, this.optsWithGlobals());
|
|
86
|
+
const docsDir = config.root;
|
|
87
|
+
const zhDir = path.resolve(docsDir, 'zh');
|
|
88
|
+
const enDir = path.resolve(docsDir, 'en');
|
|
89
|
+
if (!(await pathExists(zhDir, 'directory'))) {
|
|
90
|
+
console.error(`The directory "${cyan(zhDir)}" does not exist.`);
|
|
91
|
+
process.exitCode = 1;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const dirents = await fs.readdir(zhDir, {
|
|
95
|
+
recursive: true,
|
|
96
|
+
withFileTypes: true,
|
|
97
|
+
});
|
|
98
|
+
await Promise.all(dirents.map(async (d) => {
|
|
99
|
+
if (!d.isFile() || !/\.mdx?$/.test(d.name)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const zhFilePath = path.resolve(d.parentPath ||
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
104
|
+
d.path, d.name);
|
|
105
|
+
const zhContent = await fs.readFile(zhFilePath, 'utf-8');
|
|
106
|
+
const zhFrontmatter = matter(zhContent).data;
|
|
107
|
+
if (zhFrontmatter.i18n?.disableAutoTranslation) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const sourceSHA = crypto
|
|
111
|
+
.createHash('sha256')
|
|
112
|
+
.update(zhContent)
|
|
113
|
+
.digest('hex');
|
|
114
|
+
const enFilePath = zhFilePath.replace(zhDir, enDir);
|
|
115
|
+
let enContent;
|
|
116
|
+
let enFrontmatter;
|
|
117
|
+
if (await pathExists(enFilePath, 'file')) {
|
|
118
|
+
enContent = await fs.readFile(enFilePath, 'utf-8');
|
|
119
|
+
enFrontmatter = matter(enContent).data;
|
|
120
|
+
if (enFrontmatter.i18n?.disableAutoTranslation ||
|
|
121
|
+
enFrontmatter.sourceSHA === sourceSHA) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
await limit(async () => {
|
|
126
|
+
const relativePath = path.relative(docsDir, zhFilePath);
|
|
127
|
+
logger.info(`Translating ${cyan(relativePath)}`);
|
|
128
|
+
const isMdx = zhFilePath.endsWith('.mdx');
|
|
129
|
+
const processor = isMdx ? mdxProcessor : mdProcessor;
|
|
130
|
+
const ast = processor.parse(zhContent);
|
|
131
|
+
const normalizeImgSrcOptions = {
|
|
132
|
+
localPublicBase: path.resolve(docsDir, 'public'),
|
|
133
|
+
sourceBase: path.dirname(zhFilePath),
|
|
134
|
+
targetBase: path.dirname(enFilePath),
|
|
135
|
+
translating: 'en',
|
|
136
|
+
};
|
|
137
|
+
enContent = await translate(processor.stringify({
|
|
138
|
+
...ast,
|
|
139
|
+
children: ast.children.map((it) => normalizeImgSrc(it, normalizeImgSrcOptions)),
|
|
140
|
+
}), enContent, enFrontmatter?.i18n?.additionalPrompts ??
|
|
141
|
+
zhFrontmatter.i18n?.additionalPrompts);
|
|
142
|
+
const { data, content } = matter(enContent);
|
|
143
|
+
const newFrontmatter = { ...enFrontmatter, ...data };
|
|
144
|
+
newFrontmatter.sourceSHA = sourceSHA;
|
|
145
|
+
if (zhFrontmatter.i18n?.title?.en) {
|
|
146
|
+
newFrontmatter.title = zhFrontmatter.i18n.title.en;
|
|
147
|
+
}
|
|
148
|
+
enContent = matter.stringify(content.startsWith('\n') ? content : '\n' + content, newFrontmatter);
|
|
149
|
+
await fs.mkdir(path.dirname(enFilePath), { recursive: true });
|
|
150
|
+
await fs.writeFile(enFilePath, enContent);
|
|
151
|
+
logger.info(`${cyan(relativePath)} translated`);
|
|
152
|
+
});
|
|
153
|
+
}));
|
|
154
|
+
});
|
package/lib/config.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DoomConfig } from './utils/index.js';
|
|
1
|
+
import type { DoomConfig } from './utils/index.js';
|
|
2
2
|
export declare const defineConfig: (config: DoomConfig) => DoomConfig;
|
package/lib/plugins/api/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { addTrailingSlash } from '@rspress/core';
|
|
2
|
-
import { logger } from '@rspress/shared/logger';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import { combineWalkResult } from './utils.js';
|
|
5
4
|
import { walk } from './walk.js';
|
|
@@ -180,10 +179,6 @@ export const autoSidebarPlugin = ({ excludeRoutes, collapsed, } = {}) => {
|
|
|
180
179
|
}
|
|
181
180
|
else {
|
|
182
181
|
if (hasLang) {
|
|
183
|
-
logger.error('`lang` is configured but `locales` not, ' +
|
|
184
|
-
'thus `@rspress/plugin-auto-nav-sidebar` can not auto generate ' +
|
|
185
|
-
'navbar level config correctly!\n' +
|
|
186
|
-
'please check your config file');
|
|
187
182
|
return config;
|
|
188
183
|
}
|
|
189
184
|
const walks = versions.length
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NavItem } from '@rspress/shared';
|
|
2
|
-
import { DoomSidebar } from './walk.js';
|
|
2
|
+
import type { DoomSidebar } from './walk.js';
|
|
3
3
|
export declare function detectFilePath(rawPath: string, extensions: string[]): Promise<string | undefined>;
|
|
4
4
|
export declare function extractInfoFromFrontmatter(filePath: string, rootDir: string, extensions: string[]): Promise<{
|
|
5
5
|
realPath: string | undefined;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RspressPlugin } from '@rspress/core';
|
|
1
|
+
import type { RspressPlugin } from '@rspress/core';
|
|
2
2
|
import type { PermissionPluginOptions } from './types.js';
|
|
3
3
|
export declare const permissionPlugin: ({ localBasePath, functionresources, roletemplates, }: PermissionPluginOptions) => RspressPlugin;
|
|
@@ -4,7 +4,7 @@ export const permissionPlugin = ({ localBasePath, functionresources = [], rolete
|
|
|
4
4
|
name: 'doom-permission',
|
|
5
5
|
async addRuntimeModules(config, isProd) {
|
|
6
6
|
return {
|
|
7
|
-
...(await generateRuntimeModule(functionresources, 'permission-functionResources',
|
|
7
|
+
...(await generateRuntimeModule(functionresources, 'permission-functionResources', config.root, localBasePath, isProd, ({ items }) => items)),
|
|
8
8
|
...(await generateRuntimeModule(roletemplates, 'permission-roleTemplates', config.root, localBasePath, isProd, ({ items }) => items)),
|
|
9
9
|
};
|
|
10
10
|
},
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Content } from 'mdast';
|
|
2
2
|
import type { NormalizedReferenceSource } from './types.js';
|
|
3
|
-
export declare const normalizeImgSrc: (content: Content, { refSource, localPublicBase, publicBase, sourceBase, targetBase, force, }: {
|
|
4
|
-
refSource
|
|
3
|
+
export declare const normalizeImgSrc: (content: Content, { refSource, localPublicBase, publicBase, sourceBase, targetBase, force, translating, }: {
|
|
4
|
+
refSource?: NormalizedReferenceSource;
|
|
5
5
|
localPublicBase: string;
|
|
6
|
-
publicBase
|
|
6
|
+
publicBase?: string;
|
|
7
7
|
sourceBase: string;
|
|
8
8
|
targetBase: string;
|
|
9
9
|
force?: boolean;
|
|
10
|
+
translating?: string;
|
|
10
11
|
}) => Content;
|
|
@@ -4,27 +4,25 @@ import { isExternalUrl, removeLeadingSlash } from '@rspress/core';
|
|
|
4
4
|
import { cloneDeep } from 'es-toolkit';
|
|
5
5
|
import { visit } from 'unist-util-visit';
|
|
6
6
|
const RELATIVE_URL_PATTERN = /^\.\.?\//;
|
|
7
|
-
export const normalizeImgSrc = (content, { refSource, localPublicBase, publicBase, sourceBase, targetBase, force, }) => {
|
|
7
|
+
export const normalizeImgSrc = (content, { refSource, localPublicBase, publicBase, sourceBase, targetBase, force, translating, }) => {
|
|
8
8
|
content = cloneDeep(content);
|
|
9
9
|
const resolveImgSrc = (src, force) => {
|
|
10
10
|
if (isExternalUrl(src)) {
|
|
11
11
|
return src;
|
|
12
12
|
}
|
|
13
|
-
if (refSource
|
|
13
|
+
if (refSource?.repo) {
|
|
14
14
|
const targetDir = path.resolve(localPublicBase, '_remotes', refSource.name);
|
|
15
15
|
let sourcePath;
|
|
16
|
-
let targetPath;
|
|
17
16
|
let imageSrc;
|
|
18
17
|
if (RELATIVE_URL_PATTERN.test(src)) {
|
|
19
18
|
sourcePath = path.resolve(sourceBase, src);
|
|
20
19
|
imageSrc = path.relative(sourceBase, sourcePath);
|
|
21
|
-
targetPath = path.resolve(targetDir, imageSrc);
|
|
22
20
|
}
|
|
23
21
|
else {
|
|
24
22
|
imageSrc = removeLeadingSlash(src);
|
|
25
23
|
sourcePath = path.resolve(publicBase, imageSrc);
|
|
26
|
-
targetPath = path.resolve(targetDir, imageSrc);
|
|
27
24
|
}
|
|
25
|
+
const targetPath = path.resolve(targetDir, imageSrc);
|
|
28
26
|
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
29
27
|
if (force || !fs.existsSync(targetPath)) {
|
|
30
28
|
fs.copyFileSync(sourcePath, targetPath);
|
|
@@ -32,6 +30,14 @@ export const normalizeImgSrc = (content, { refSource, localPublicBase, publicBas
|
|
|
32
30
|
return `/_remotes/${refSource.name}/${imageSrc}`;
|
|
33
31
|
}
|
|
34
32
|
else if (!RELATIVE_URL_PATTERN.test(src)) {
|
|
33
|
+
if (translating &&
|
|
34
|
+
src.startsWith('/zh/') &&
|
|
35
|
+
fs.existsSync(path.resolve(localPublicBase, translating, src.replace('/zh/', '')))) {
|
|
36
|
+
return src.replace('/zh/', `/${translating}/`);
|
|
37
|
+
}
|
|
38
|
+
return src;
|
|
39
|
+
}
|
|
40
|
+
if (translating && fs.existsSync(path.resolve(targetBase, src))) {
|
|
35
41
|
return src;
|
|
36
42
|
}
|
|
37
43
|
const targetSrc = path.relative(targetBase, path.resolve(sourceBase, src));
|
|
@@ -3,7 +3,7 @@ import remarkFrontmatter from 'remark-frontmatter';
|
|
|
3
3
|
import remarkGfm from 'remark-gfm';
|
|
4
4
|
import remarkMdx from 'remark-mdx';
|
|
5
5
|
import remarkParse from 'remark-parse';
|
|
6
|
-
import remarkStringify from 'remark-stringify';
|
|
6
|
+
import remarkStringify, {} from 'remark-stringify';
|
|
7
7
|
import { unified } from 'unified';
|
|
8
8
|
import { red } from 'yoctocolors';
|
|
9
9
|
/**
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ExternalSiteProps } from './ExternalSite.js';
|
|
1
|
+
import type { ExternalSiteProps } from './ExternalSite.js';
|
|
2
2
|
export declare const ExternalApisOverview: ({ name }: ExternalSiteProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default ExternalApisOverview;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* modified based on @see https://github.com/crdsdev/doc/blob/main/template/doc.html
|
|
3
3
|
*/
|
|
4
|
-
import { OpenAPIV3_1 } from 'openapi-types';
|
|
4
|
+
import type { OpenAPIV3_1 } from 'openapi-types';
|
|
5
5
|
export interface K8sCrdProps {
|
|
6
6
|
/**
|
|
7
7
|
* The `metadata.name` of the CustomResourceDefinition
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
3
|
+
import BananaSlug from 'github-slugger';
|
|
3
4
|
import { Children, useMemo, useState } from 'react';
|
|
4
5
|
export const HeadingTitle = ({ slug, slugger, level, children, }) => {
|
|
5
6
|
const [X] = useState(getCustomMDXComponent);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useLang } from '@rspress/core/runtime';
|
|
2
|
-
import { TRANSLATIONS } from '../translation.js';
|
|
3
2
|
import { useCallback } from 'react';
|
|
3
|
+
import { TRANSLATIONS } from '../translation.js';
|
|
4
4
|
export const useTranslation = () => {
|
|
5
5
|
const lang = (useLang() || 'zh');
|
|
6
6
|
const translations = TRANSLATIONS[lang];
|
package/lib/utils/fs.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function pathExists(path: string): Promise<boolean>;
|
|
1
|
+
export declare function pathExists(path: string, type?: 'file' | 'directory'): Promise<boolean>;
|
|
2
2
|
export declare function readJson<T>(path: string): Promise<T>;
|
package/lib/utils/fs.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
|
-
export async function pathExists(path) {
|
|
2
|
+
export async function pathExists(path, type) {
|
|
3
3
|
try {
|
|
4
|
-
await fs.
|
|
4
|
+
const stats = await fs.stat(path);
|
|
5
|
+
if (type === 'file') {
|
|
6
|
+
return stats.isFile();
|
|
7
|
+
}
|
|
8
|
+
if (type === 'directory') {
|
|
9
|
+
return stats.isDirectory();
|
|
10
|
+
}
|
|
5
11
|
return true;
|
|
6
12
|
}
|
|
7
13
|
catch {
|
package/lib/utils/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StringMapper } from '../shared/types.js';
|
|
1
|
+
import type { StringMapper } from '../shared/types.js';
|
|
2
2
|
export declare const baseResolve: (...paths: string[]) => string;
|
|
3
3
|
export declare const pkgResolve: (...paths: string[]) => string;
|
|
4
4
|
export declare const resolveStaticConfig: <T = unknown>(filepath: string) => Promise<T>;
|
package/lib/utils/helpers.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { glob } from 'tinyglobby';
|
|
3
4
|
import { parse } from 'yaml';
|
|
4
|
-
import { BASE_DIR, PKG_DIR } from './constants.js';
|
|
5
5
|
import { JSON_EXTENSION, YAML_EXTENSIONS } from '../cli/constants.js';
|
|
6
|
-
import {
|
|
6
|
+
import { BASE_DIR, PKG_DIR } from './constants.js';
|
|
7
7
|
export const baseResolve = (...paths) => path.resolve(BASE_DIR, ...paths);
|
|
8
8
|
export const pkgResolve = (...paths) => path.resolve(PKG_DIR, ...paths);
|
|
9
9
|
export const resolveStaticConfig = async (filepath) => {
|
package/lib/utils/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserConfig } from '@rspress/core';
|
|
1
|
+
import type { UserConfig } from '@rspress/core';
|
|
2
2
|
import type { ApiPluginOptions } from '../plugins/api/types.js';
|
|
3
3
|
import type { AutoSidebarPluginOptions } from '../plugins/index.js';
|
|
4
4
|
import type { PermissionPluginOptions } from '../plugins/permission/types.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"lint:tsc": "tsc -b",
|
|
36
36
|
"prepare": "simple-git-hooks && patch-package",
|
|
37
37
|
"prepublishOnly": "yarn build",
|
|
38
|
-
"swc-node": "node --enable-source-maps --import @swc-node/register/esm-register"
|
|
38
|
+
"swc-node": "node --enable-source-maps --import @swc-node/register/esm-register",
|
|
39
|
+
"translate": "yarn doom translate fixture-docs"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@inquirer/prompts": "^7.3.2",
|
|
@@ -49,7 +50,9 @@
|
|
|
49
50
|
"es-toolkit": "^1.32.0",
|
|
50
51
|
"html-tag-names": "^2.1.0",
|
|
51
52
|
"mermaid": "^11.4.1",
|
|
53
|
+
"openai": "^5.0.0-alpha.0",
|
|
52
54
|
"openapi-types": "^12.1.3",
|
|
55
|
+
"p-ratelimit": "^1.0.1",
|
|
53
56
|
"picomatch": "^4.0.2",
|
|
54
57
|
"react-markdown": "^8.0.7",
|
|
55
58
|
"rehype-raw": "^6.1.1",
|
|
@@ -82,7 +85,7 @@
|
|
|
82
85
|
"prettier-plugin-pkg": "^0.18.1",
|
|
83
86
|
"simple-git-hooks": "^2.11.1",
|
|
84
87
|
"typescript": "^5.7.3",
|
|
85
|
-
"typescript-eslint": "^8.
|
|
88
|
+
"typescript-eslint": "^8.25.0"
|
|
86
89
|
},
|
|
87
90
|
"publishConfig": {
|
|
88
91
|
"access": "public"
|