@alauda/doom 2.0.0 → 2.2.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/global.d.ts +0 -1
- package/lib/cli/translate.js +6 -8
- package/lib/plugins/auto-sidebar/utils.d.ts +5 -4
- package/lib/plugins/replace/utils.js +2 -2
- package/lib/remark-lint/index.d.ts +1 -0
- package/lib/remark-lint/index.js +1 -0
- package/lib/remark-lint/title-required.d.ts +2 -0
- package/lib/remark-lint/title-required.js +44 -0
- package/lib/remarkrc.js +2 -1
- package/lib/runtime/index.d.ts +1 -0
- package/lib/runtime/index.js +2 -0
- package/lib/utils/fs.js +1 -1
- package/package.json +4 -1
package/global.d.ts
CHANGED
package/lib/cli/translate.js
CHANGED
|
@@ -8,7 +8,7 @@ import { removeLeadingSlash } from '@rspress/shared';
|
|
|
8
8
|
import { Command } from 'commander';
|
|
9
9
|
import ejs from 'ejs';
|
|
10
10
|
import matter from 'gray-matter';
|
|
11
|
-
import {
|
|
11
|
+
import { OpenAI, RateLimitError } from 'openai';
|
|
12
12
|
import { pRateLimit } from 'p-ratelimit';
|
|
13
13
|
import { glob } from 'tinyglobby';
|
|
14
14
|
import { cyan, red } from 'yoctocolors';
|
|
@@ -83,7 +83,7 @@ The text for translation is provided below, within triple quotes:
|
|
|
83
83
|
<% } %>
|
|
84
84
|
`.trim();
|
|
85
85
|
let openai;
|
|
86
|
-
const openaiModel = process.env.
|
|
86
|
+
const openaiModel = process.env.ALAUDA_OPENAI_MODEL || 'gpt-5.4-mini';
|
|
87
87
|
const resolveTerms = async (sourceLang, targetLang, sourceContent) => {
|
|
88
88
|
const parsedTerms = await parseTerms();
|
|
89
89
|
// Filter terms that exist in source content and have translations for both source and target languages
|
|
@@ -202,11 +202,9 @@ export const translateWithChunks = async (options) => {
|
|
|
202
202
|
};
|
|
203
203
|
export const translate = async ({ source, sourceContent, target, systemPrompt, userPrompt = '', additionalPrompts = '', isChunk = false, }) => {
|
|
204
204
|
if (!openai) {
|
|
205
|
-
openai = new
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
apiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
209
|
-
apiVersion: process.env.OPENAI_API_VERSION || '2025-04-01-preview',
|
|
205
|
+
openai = new OpenAI({
|
|
206
|
+
baseURL: process.env.ALAUDA_OPENAI_BASE_URL,
|
|
207
|
+
apiKey: process.env.ALAUDA_OPENAI_API_KEY,
|
|
210
208
|
});
|
|
211
209
|
}
|
|
212
210
|
const sourceLang = Language[source];
|
|
@@ -267,7 +265,7 @@ export const translateCommand = new Command('translate')
|
|
|
267
265
|
.option('-s, --source <language>', `Document source language, one of ${supportedLanguages}`, 'en')
|
|
268
266
|
.option('-t, --target <language>', `Document target language, one of ${supportedLanguages}`, 'zh')
|
|
269
267
|
.requiredOption('-g, --glob <path...>', 'Glob patterns of source dirs/files to translate')
|
|
270
|
-
.option('-C, --copy [boolean]', '
|
|
268
|
+
.option('-C, --copy [boolean]', 'Whether to copy relative assets to the target directory instead of following links', parseBoolean, false)
|
|
271
269
|
.action(async function (root) {
|
|
272
270
|
const { source, target, glob: globs, copy, force, ...globalOptions } = this.optsWithGlobals();
|
|
273
271
|
if (!Object.hasOwn(Language, source) ||
|
|
@@ -8,10 +8,11 @@ export declare function extractInfoFromFrontmatter(filePath: string, rootDir: st
|
|
|
8
8
|
context: string | undefined;
|
|
9
9
|
weight?: number;
|
|
10
10
|
}>;
|
|
11
|
-
export
|
|
11
|
+
export interface WalkResult {
|
|
12
12
|
nav: NavItem[];
|
|
13
13
|
sidebar: Record<string, DoomSidebar[]>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
}
|
|
15
|
+
export declare function combineWalkResult(walks: WalkResult[], versions: string[]): {
|
|
16
|
+
nav: Record<string, NavItem[]>;
|
|
17
|
+
sidebar: Record<string, DoomSidebar[]>;
|
|
17
18
|
};
|
|
@@ -39,8 +39,8 @@ export const mdProcessor = unified()
|
|
|
39
39
|
.freeze();
|
|
40
40
|
export const mdxProcessor = mdProcessor().use(remarkMdx).freeze();
|
|
41
41
|
export const getFrontmatterNode = (ast) => {
|
|
42
|
-
const firstNode = ast.children
|
|
43
|
-
return firstNode
|
|
42
|
+
const firstNode = ast.children.at(0);
|
|
43
|
+
return firstNode?.type === 'yaml' ? firstNode : undefined;
|
|
44
44
|
};
|
|
45
45
|
const { CI } = process.env;
|
|
46
46
|
export const isCI = CI !== 'false' && !!CI;
|
|
@@ -16,6 +16,7 @@ export * from './no-paragraph-indent.ts';
|
|
|
16
16
|
export * from './no-unmatched-anchor.ts';
|
|
17
17
|
export * from './site.ts';
|
|
18
18
|
export * from './table-size.ts';
|
|
19
|
+
export * from './title-required.ts';
|
|
19
20
|
export * from './unit-case.ts';
|
|
20
21
|
declare const doomLint: Plugin<[], Root>;
|
|
21
22
|
export default doomLint;
|
package/lib/remark-lint/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./no-paragraph-indent.js";
|
|
|
15
15
|
export * from "./no-unmatched-anchor.js";
|
|
16
16
|
export * from "./site.js";
|
|
17
17
|
export * from "./table-size.js";
|
|
18
|
+
export * from "./title-required.js";
|
|
18
19
|
export * from "./unit-case.js";
|
|
19
20
|
const doomLint = function () {
|
|
20
21
|
this.use(() => remarkMessageControl({
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { toString } from 'mdast-util-to-string';
|
|
2
|
+
import { lintRule } from 'unified-lint-rule';
|
|
3
|
+
import { visitParents } from 'unist-util-visit-parents';
|
|
4
|
+
import { parse } from 'yaml';
|
|
5
|
+
export const titleRequired = lintRule('doom-lint:title-required', (root, vfile) => {
|
|
6
|
+
let frontmatterTitle;
|
|
7
|
+
let headingTitle;
|
|
8
|
+
visitParents(root, (node, parents) => {
|
|
9
|
+
if (node.type === 'yaml') {
|
|
10
|
+
frontmatterTitle = parse(node.value)
|
|
11
|
+
?.title;
|
|
12
|
+
}
|
|
13
|
+
function checkHeadingTitle(title) {
|
|
14
|
+
if (headingTitle) {
|
|
15
|
+
vfile.message('Multiple level 1 headings found, remove redundant heading or consolidate them into one.', {
|
|
16
|
+
ancestors: [...parents, node],
|
|
17
|
+
place: node.position,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
headingTitle = title;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (node.type === 'heading') {
|
|
25
|
+
if (node.depth === 1) {
|
|
26
|
+
checkHeadingTitle(toString(node));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (node.type === 'html') {
|
|
30
|
+
for (const [, title] of node.value.matchAll(/<h1[^>]*>([\s\S]*?)<\/h1>/gi)) {
|
|
31
|
+
checkHeadingTitle(title);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (node.type === 'mdxJsxFlowElement' ||
|
|
35
|
+
node.type === 'mdxJsxTextElement') {
|
|
36
|
+
if (node.name === 'h1') {
|
|
37
|
+
checkHeadingTitle(toString(node));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (!frontmatterTitle && !headingTitle) {
|
|
42
|
+
vfile.message('Title is required. Please add a title in the frontmatter or as a heading.', root);
|
|
43
|
+
}
|
|
44
|
+
});
|
package/lib/remarkrc.js
CHANGED
|
@@ -10,7 +10,7 @@ import remarkLintLintMatchPunctuation from 'remark-lint-match-punctuation';
|
|
|
10
10
|
import remarkLintNoChinesePunctuationInNumber from 'remark-lint-no-chinese-punctuation-in-number';
|
|
11
11
|
import remarkLintNoDuplicateHeadingsInSection from 'remark-lint-no-duplicate-headings-in-section';
|
|
12
12
|
import remarkLintNoHiddenTableCell from 'remark-lint-no-hidden-table-cell';
|
|
13
|
-
import doomLint, { checkDeadLinks, noDeepHeading, noDeepList, noMultiOpenAPIPaths, noParagraphIndent, noUnmatchedAnchor, site, tableSize, unitCase, } from "./remark-lint/index.js";
|
|
13
|
+
import doomLint, { checkDeadLinks, noDeepHeading, noDeepList, noMultiOpenAPIPaths, noParagraphIndent, noUnmatchedAnchor, site, tableSize, titleRequired, unitCase, } from "./remark-lint/index.js";
|
|
14
14
|
export default {
|
|
15
15
|
plugins: [
|
|
16
16
|
remarkDirective,
|
|
@@ -31,6 +31,7 @@ export default {
|
|
|
31
31
|
noUnmatchedAnchor,
|
|
32
32
|
site,
|
|
33
33
|
tableSize,
|
|
34
|
+
titleRequired,
|
|
34
35
|
unitCase,
|
|
35
36
|
],
|
|
36
37
|
};
|
package/lib/runtime/index.d.ts
CHANGED
package/lib/runtime/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
/// <reference path="../../shim.d.ts" />
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
4
4
|
/// <reference path="../../global.d.ts" preserve="true" />
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
6
|
+
/// <reference path="../types.ts" preserve="true" />
|
|
5
7
|
export * from '../terms.js';
|
|
6
8
|
export * from './components/index.js';
|
|
7
9
|
export * from './hooks/index.js';
|
package/lib/utils/fs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"node": ">=22.18.0"
|
|
15
15
|
},
|
|
16
16
|
"bin": "lib/cli/index.js",
|
|
17
|
+
"imports": {
|
|
18
|
+
"#*": "./src/*"
|
|
19
|
+
},
|
|
17
20
|
"exports": {
|
|
18
21
|
"./assets/*": "./assets/*",
|
|
19
22
|
"./config": "./lib/config.js",
|