@alauda/doom 0.18.9 → 0.18.11
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 +4 -1
- package/lib/cli/index.js +1 -0
- package/lib/cli/load-config.d.ts +1 -1
- package/lib/cli/load-config.js +4 -3
- package/lib/cli/translate.js +12 -6
- package/lib/plugins/auto-sidebar/index.js +4 -3
- package/lib/shared/constants.d.ts +1 -0
- package/lib/shared/constants.js +1 -0
- package/lib/types.d.ts +1 -0
- package/package.json +2 -1
package/lib/cli/export.js
CHANGED
|
@@ -15,7 +15,10 @@ export const exportCommand = new Command('export')
|
|
|
15
15
|
.action(async function (root) {
|
|
16
16
|
setNodeEnv('production');
|
|
17
17
|
const { port, host, ...globalOptions } = this.optsWithGlobals();
|
|
18
|
-
let { config } = await loadConfig(root,
|
|
18
|
+
let { config } = await loadConfig(root, {
|
|
19
|
+
...globalOptions,
|
|
20
|
+
export: true,
|
|
21
|
+
});
|
|
19
22
|
const outDir = config.outDir;
|
|
20
23
|
if (!(await pathExists(path.resolve(outDir, 'index.html'), 'file'))) {
|
|
21
24
|
logger.error('Please build the documentation first');
|
package/lib/cli/index.js
CHANGED
|
@@ -36,6 +36,7 @@ program
|
|
|
36
36
|
2. translate ignore hash equality check and original text`, parseBoolean, false)
|
|
37
37
|
.option('-i, --ignore [boolean]', 'Ignore internal routes', parseBoolean, false)
|
|
38
38
|
.option('-d, --download [boolean]', 'Display download pdf link on nav bar', parseBoolean, false)
|
|
39
|
+
.option('-e, --export [boolean]', 'Run or build in exporting PDF mode, `apis/**` and `*/apis/**` routes will be ignored automatically', parseBoolean, false)
|
|
39
40
|
.option('--no-open [boolean]', 'Do not open the browser after starting the server')
|
|
40
41
|
.command('dev', { isDefault: true })
|
|
41
42
|
.description('Start the development server')
|
package/lib/cli/load-config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type UserConfig } from '@rspress/core';
|
|
2
2
|
import type { GlobalCliOptions } from '../types.js';
|
|
3
|
-
export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, ignore, force, open, lazy, }?: GlobalCliOptions): Promise<{
|
|
3
|
+
export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, }?: GlobalCliOptions): Promise<{
|
|
4
4
|
config: UserConfig;
|
|
5
5
|
filepath?: string;
|
|
6
6
|
}>;
|
package/lib/cli/load-config.js
CHANGED
|
@@ -19,7 +19,7 @@ const zhLocaleConfig = {
|
|
|
19
19
|
prevPageText: '上一页',
|
|
20
20
|
nextPageText: '下一页',
|
|
21
21
|
};
|
|
22
|
-
const getCommonConfig = ({ config, root, configFilePath, base, version, download, ignore, force, open, lazy, }) => {
|
|
22
|
+
const getCommonConfig = ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, }) => {
|
|
23
23
|
const fallbackToZh = 'lang' in config && !config.lang;
|
|
24
24
|
root = resolveDocRoot(CWD, root, config.root);
|
|
25
25
|
const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
|
|
@@ -69,7 +69,7 @@ const getCommonConfig = ({ config, root, configFilePath, base, version, download
|
|
|
69
69
|
apiPlugin({
|
|
70
70
|
localBasePath,
|
|
71
71
|
}),
|
|
72
|
-
autoSidebarPlugin({ ignore }),
|
|
72
|
+
autoSidebarPlugin({ export: export_, ignore }),
|
|
73
73
|
directivesPlugin(),
|
|
74
74
|
globalPlugin({ version, download }),
|
|
75
75
|
mermaidPlugin(),
|
|
@@ -134,7 +134,7 @@ const getCommonConfig = ({ config, root, configFilePath, base, version, download
|
|
|
134
134
|
const findConfig = (basePath) => {
|
|
135
135
|
return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
|
|
136
136
|
};
|
|
137
|
-
export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, ignore, force, open, lazy, } = {}) {
|
|
137
|
+
export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, } = {}) {
|
|
138
138
|
let configFilePath;
|
|
139
139
|
if (configFile) {
|
|
140
140
|
configFilePath = path.resolve(configFile);
|
|
@@ -191,6 +191,7 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
|
|
|
191
191
|
base,
|
|
192
192
|
version,
|
|
193
193
|
download,
|
|
194
|
+
export: export_,
|
|
194
195
|
ignore,
|
|
195
196
|
force,
|
|
196
197
|
open,
|
package/lib/cli/translate.js
CHANGED
|
@@ -12,6 +12,8 @@ import matter from 'gray-matter';
|
|
|
12
12
|
import { AzureOpenAI, RateLimitError } from 'openai';
|
|
13
13
|
import { pRateLimit } from 'p-ratelimit';
|
|
14
14
|
import { glob } from 'tinyglobby';
|
|
15
|
+
import { fetchApi } from 'x-fetch';
|
|
16
|
+
import { parse } from 'yaml';
|
|
15
17
|
import { cyan, red } from 'yoctocolors';
|
|
16
18
|
import { mdProcessor, mdxProcessor, normalizeImgSrc, } from '../plugins/index.js';
|
|
17
19
|
import { pathExists } from '../utils/index.js';
|
|
@@ -32,10 +34,7 @@ const DEFAULT_SYSTEM_PROMPT = `
|
|
|
32
34
|
- MDX 组件中包含的内容需要翻译,MDX 组件参数的值不需要翻译,但以下这些特殊的 MDX 组件参数值需要翻译
|
|
33
35
|
* 组件示例: <Tab label="参数值">组件包含的内容</Tab>,label 是 key 不用翻译,"参数值" 需要翻译
|
|
34
36
|
- 以下是常见的相关术语词汇对应表(中文 -> English)
|
|
35
|
-
|
|
36
|
-
* 灵雀云 -> Alauda
|
|
37
|
-
* 容器组 -> Pods
|
|
38
|
-
* global 集群 -> global cluster
|
|
37
|
+
<%= terms %>
|
|
39
38
|
- 如果存在下列注释,请保留不用翻译,更不要修改注释内容
|
|
40
39
|
- {/* release-notes-for-bugs */}
|
|
41
40
|
- <!-- release-notes-for-bugs -->
|
|
@@ -64,22 +63,29 @@ const DEFAULT_SYSTEM_PROMPT = `
|
|
|
64
63
|
<%= additionalPrompts %>
|
|
65
64
|
`.trim();
|
|
66
65
|
let openai;
|
|
66
|
+
const resolveTerms = async () => {
|
|
67
|
+
const terms = await fetchApi('https://gitlab-ce.alauda.cn/alauda-public/product-doc-guide/-/raw/main/terms.yaml', { type: 'text' });
|
|
68
|
+
const parsedTerms = parse(terms);
|
|
69
|
+
return parsedTerms.map(({ en, zh = en }) => ` * ${zh} -> ${en}`).join('\n');
|
|
70
|
+
};
|
|
67
71
|
export const translate = async ({ source, sourceContent, target, targetContent = '', systemPrompt, userPrompt = '', additionalPrompts = '', }) => {
|
|
68
72
|
if (!openai) {
|
|
69
73
|
openai = new AzureOpenAI({
|
|
70
74
|
endpoint: process.env.AZURE_OPENAI_ENDPOINT ||
|
|
71
75
|
'https://apt-docs-openai.openai.azure.com',
|
|
72
76
|
apiKey: process.env.AZURE_OPENAI_API_KEY || 'doom',
|
|
73
|
-
apiVersion: process.env.OPENAI_API_VERSION || '2025-
|
|
77
|
+
apiVersion: process.env.OPENAI_API_VERSION || '2025-03-01-preview',
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
80
|
const sourceLang = LANGUAGE_CODES[source];
|
|
77
81
|
const targetLang = LANGUAGE_CODES[target];
|
|
82
|
+
const terms = await resolveTerms();
|
|
83
|
+
logger.debug('Resolved terms:\n' + terms);
|
|
78
84
|
const { choices } = await openai.beta.chat.completions.parse({
|
|
79
85
|
messages: [
|
|
80
86
|
{
|
|
81
87
|
role: 'system',
|
|
82
|
-
content: await render(systemPrompt?.trim() || DEFAULT_SYSTEM_PROMPT, { sourceLang, targetLang, userPrompt, additionalPrompts }, { async: true }),
|
|
88
|
+
content: await render(systemPrompt?.trim() || DEFAULT_SYSTEM_PROMPT, { sourceLang, targetLang, userPrompt, additionalPrompts, terms }, { async: true }),
|
|
83
89
|
},
|
|
84
90
|
{
|
|
85
91
|
role: 'user',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { addTrailingSlash, } from '@rspress/core';
|
|
3
|
+
import { APIS_ROUTES } from '../../shared/index.js';
|
|
3
4
|
import { combineWalkResult } from './utils.js';
|
|
4
5
|
import { walk } from './walk.js';
|
|
5
6
|
// Scan all the directories and files in the work directory(such as `docs`), and then generate the nav and sidebar configuration according to the directory structure.
|
|
@@ -154,16 +155,16 @@ function processLocales(langs, versions, root, defaultLang, defaultVersion, exte
|
|
|
154
155
|
}));
|
|
155
156
|
}
|
|
156
157
|
const defaultExtensions = ['.mdx', '.md', '.tsx', '.jsx', '.ts', '.js'];
|
|
157
|
-
const APIS_ROUTES = ['apis/**', '*/apis/**'];
|
|
158
158
|
export const autoSidebar = async (config, { ignore, export: export_ }) => {
|
|
159
159
|
const excludeRoutes = (ignore && config.internalRoutes) || [];
|
|
160
160
|
const route = (config.route ??= {});
|
|
161
161
|
if (export_ || excludeRoutes.length) {
|
|
162
|
+
const exclude = (route.exclude ??= []);
|
|
163
|
+
exclude.push(...excludeRoutes);
|
|
164
|
+
// only exclude apis routes for sidebar but not site data to avoid dead links
|
|
162
165
|
if (export_) {
|
|
163
166
|
excludeRoutes.push(...APIS_ROUTES);
|
|
164
167
|
}
|
|
165
|
-
const exclude = (route.exclude ??= []);
|
|
166
|
-
exclude.push(...excludeRoutes);
|
|
167
168
|
}
|
|
168
169
|
config.themeConfig ??= {};
|
|
169
170
|
config.themeConfig.locales ??= config.locales || [];
|
package/lib/shared/constants.js
CHANGED
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": "https://gitlab-ce.alauda.cn/idp/Doom.git",
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"simple-git-hooks": "^2.12.1",
|
|
98
98
|
"typescript": "^5.8.3",
|
|
99
99
|
"typescript-eslint": "^8.29.1",
|
|
100
|
+
"x-fetch": "^0.2.4",
|
|
100
101
|
"yarn-berry-deduplicate": "^6.1.1"
|
|
101
102
|
},
|
|
102
103
|
"publishConfig": {
|