@alauda/doom 0.23.6 → 0.23.8
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/translate.js +2 -2
- package/lib/runtime/components/OpenAPIPath.js +5 -4
- package/lib/runtime/components/OpenAPIRef.d.ts +2 -1
- package/lib/runtime/components/OpenAPIRef.js +7 -3
- package/lib/runtime/components/_HeadingTitle.d.ts +2 -1
- package/lib/runtime/components/_HeadingTitle.js +11 -5
- package/package.json +1 -1
package/lib/cli/translate.js
CHANGED
|
@@ -50,9 +50,9 @@ const DEFAULT_SYSTEM_PROMPT = `
|
|
|
50
50
|
- 语句不通顺,指出位置,不需要给出修改意见,意译时修复
|
|
51
51
|
- 晦涩难懂,模棱两可,不易理解,可以尝试给出解释
|
|
52
52
|
3. 根据第一步直译的结果和第二步指出的问题,重新进行意译,保证内容的原意的基础上,使其更易于理解,更符合<%= targetLang %>技术文档的表达习惯,同时保持原有的格式不变
|
|
53
|
-
4. 当存在之前翻译过的<%= targetLang %>文档时,将第三步的结果分段与之前的<%= targetLang
|
|
53
|
+
4. 当存在之前翻译过的<%= targetLang %>文档时,将第三步的结果分段与之前的<%= targetLang %>文档细致地比较,不要遗漏任何新的分段(包括文本、代码块、图片、超链接等等),如果分段内翻译结果意思相近,仅仅表达方式不同的,且没有新增任何内容时,则该分段只需要保持之前翻译过的内容即可,不需要重复翻译
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
最终只需要完整输出最后一步的结果,不需要输出任何提及提示词或之前步骤的内容,也不要只返回新增的内容。
|
|
56
56
|
|
|
57
57
|
<%= userPrompt %>
|
|
58
58
|
|
|
@@ -5,7 +5,7 @@ import openapisMap from 'doom-@api-openapisMap';
|
|
|
5
5
|
import virtual from 'doom-@api-virtual';
|
|
6
6
|
import BananaSlug from 'github-slugger';
|
|
7
7
|
import { OpenAPIV3 } from 'openapi-types';
|
|
8
|
-
import { Fragment, useMemo, useState } from 'react';
|
|
8
|
+
import { Fragment, useId, useMemo, useState } from 'react';
|
|
9
9
|
import { omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
10
10
|
import { OpenAPIProperties, OpenAPIProperty, OpenAPIRef } from './OpenAPIRef.js';
|
|
11
11
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
@@ -93,6 +93,7 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
93
93
|
const [X] = useState(getCustomMDXComponent);
|
|
94
94
|
const { page } = usePageData();
|
|
95
95
|
const pathPrefix = pathPrefix_ ?? (virtual.pathPrefix || '');
|
|
96
|
+
const uid = useId();
|
|
96
97
|
const slugger = useMemo(() => new BananaSlug(), []);
|
|
97
98
|
const [pathItem, openapi, openapiPath, refs] = useMemo(() => {
|
|
98
99
|
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
@@ -115,7 +116,7 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
115
116
|
console.error(`No OpenAPI path definition found for ${path}`);
|
|
116
117
|
return null;
|
|
117
118
|
}
|
|
118
|
-
return (_jsxs(_Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, level: 2, children: [pathPrefix, path] }), pathItem.parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 3, children: "Common Parameters" }), _jsx(OpenAPIParameters, { parameters: pathItem.parameters, openapi: openapi })] })), Object.values(OpenAPIV3.HttpMethods).map((method) => {
|
|
119
|
+
return (_jsxs(_Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, uid: uid, level: 2, children: [pathPrefix, path] }), pathItem.parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, uid: uid, level: 3, children: "Common Parameters" }), _jsx(OpenAPIParameters, { parameters: pathItem.parameters, openapi: openapi })] })), Object.values(OpenAPIV3.HttpMethods).map((method) => {
|
|
119
120
|
if (!pathItem[method]) {
|
|
120
121
|
return null;
|
|
121
122
|
}
|
|
@@ -127,9 +128,9 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
127
128
|
const requestBodySchema = requestBodyRef
|
|
128
129
|
? resolveRef(openapi, requestBodyRef)
|
|
129
130
|
: undefined;
|
|
130
|
-
return (_jsxs(Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, level: 3, children: [_jsx("code", { children: method }), summary] }), _jsx(Markdown, { children: description }), parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Parameters" }), _jsx(OpenAPIParameters, { parameters: parameters, openapi: openapi })] })), requestBodySchema && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Request Body" }), _jsxs(X.p, { children: [_jsx(RefLink, { "$ref": requestBodyRef }), requestBodySchema.required && _jsx(Badge, { children: "required" })] })] })), responses && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Response" }), _jsx(OpenAPIResponses, { responses: responses, openapi: openapi })] }))] }, method));
|
|
131
|
+
return (_jsxs(Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, uid: uid, level: 3, children: [_jsx("code", { children: method }), summary] }), _jsx(Markdown, { children: description }), parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, uid: uid, level: 4, children: "Parameters" }), _jsx(OpenAPIParameters, { parameters: parameters, openapi: openapi })] })), requestBodySchema && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, uid: uid, level: 4, children: "Request Body" }), _jsxs(X.p, { children: [_jsx(RefLink, { "$ref": requestBodyRef }), requestBodySchema.required && _jsx(Badge, { children: "required" })] })] })), responses && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, uid: uid, level: 4, children: "Response" }), _jsx(OpenAPIResponses, { responses: responses, openapi: openapi })] }))] }, method));
|
|
131
132
|
}), refs?.map((ref) => {
|
|
132
|
-
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, collectRefs: false }, ref));
|
|
133
|
+
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, uid: uid, collectRefs: false }, ref));
|
|
133
134
|
})] }));
|
|
134
135
|
};
|
|
135
136
|
export default OpenAPIPath;
|
|
@@ -8,6 +8,7 @@ export interface OpenAPIRefProps {
|
|
|
8
8
|
* The specific path to the OpenAPI schema, otherwise the first matched will be used.
|
|
9
9
|
*/
|
|
10
10
|
openapiPath?: string;
|
|
11
|
+
uid?: string;
|
|
11
12
|
collectRefs?: boolean;
|
|
12
13
|
}
|
|
13
14
|
export declare const OpenAPIProperty: ({ name, property, openapi, }: {
|
|
@@ -19,5 +20,5 @@ export declare const OpenAPIProperties: ({ properties, openapi, }: {
|
|
|
19
20
|
properties: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject>;
|
|
20
21
|
openapi: OpenAPIV3_1.Document;
|
|
21
22
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
-
export declare const OpenAPIRef: ({ schema, openapiPath: openapiPath_, collectRefs, }: OpenAPIRefProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
23
|
+
export declare const OpenAPIRef: ({ schema, openapiPath: openapiPath_, uid, collectRefs, }: OpenAPIRefProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
23
24
|
export default OpenAPIRef;
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { usePageData } from '@rspress/core/runtime';
|
|
3
3
|
import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
4
4
|
import openapisMap from 'doom-@api-openapisMap';
|
|
5
|
-
import { useMemo, useState } from 'react';
|
|
5
|
+
import { useId, useMemo, useState } from 'react';
|
|
6
6
|
import { modelName, omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
7
7
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
8
8
|
import { Markdown } from './_Markdown.js';
|
|
@@ -69,8 +69,12 @@ const getRefsForSchema = (openapi, schema, knownRefs) => {
|
|
|
69
69
|
collectRefs(refSchema);
|
|
70
70
|
return Array.from(refs);
|
|
71
71
|
};
|
|
72
|
-
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, collectRefs = true, }) => {
|
|
72
|
+
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, uid, collectRefs = true, }) => {
|
|
73
73
|
const { page } = usePageData();
|
|
74
|
+
const innerUid = useId();
|
|
75
|
+
if (uid == null) {
|
|
76
|
+
uid = innerUid;
|
|
77
|
+
}
|
|
74
78
|
const [schemaItem, openapi, openapiPath] = useMemo(() => {
|
|
75
79
|
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
76
80
|
if (openapiPath_ && pathname !== openapiPath_) {
|
|
@@ -92,6 +96,6 @@ export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, collectRefs = tr
|
|
|
92
96
|
return getRefsForSchema(openapi, schema, omitRoutePathRefs(page.routePath));
|
|
93
97
|
}
|
|
94
98
|
}, [collectRefs, openapi, page.routePath, schema]);
|
|
95
|
-
return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slug: schema, level: 2, children: modelName(schema) }), _jsx(Markdown, { children: schemaItem.description }), schemaItem.properties && (_jsx(OpenAPIProperties, { properties: schemaItem.properties, openapi: openapi })), refs?.map((schema) => (_jsx(OpenAPIRef, { schema: schema, openapiPath: openapiPath, collectRefs: false }, schema)))] }));
|
|
99
|
+
return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { uid: uid, slug: schema, level: 2, children: modelName(schema) }), _jsx(Markdown, { children: schemaItem.description }), schemaItem.properties && (_jsx(OpenAPIProperties, { properties: schemaItem.properties, openapi: openapi })), refs?.map((schema) => (_jsx(OpenAPIRef, { schema: schema, openapiPath: openapiPath, uid: uid, collectRefs: false }, schema)))] }));
|
|
96
100
|
};
|
|
97
101
|
export default OpenAPIRef;
|
|
@@ -3,7 +3,8 @@ import { type ReactNode } from 'react';
|
|
|
3
3
|
export interface HeadingTitleProps {
|
|
4
4
|
slug?: string;
|
|
5
5
|
slugger?: BananaSlug;
|
|
6
|
+
uid?: string;
|
|
6
7
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
7
8
|
children: ReactNode;
|
|
8
9
|
}
|
|
9
|
-
export declare const HeadingTitle: ({ slug, slugger, level, children, }: HeadingTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare const HeadingTitle: ({ slug, slugger, uid, level, children, }: HeadingTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,15 +2,21 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
3
3
|
import BananaSlug from 'github-slugger';
|
|
4
4
|
import { Children, useMemo, useState } from 'react';
|
|
5
|
-
|
|
5
|
+
// TODO: use context to simplify the usage of `slugger` and `uid`
|
|
6
|
+
export const HeadingTitle = ({ slug, slugger, uid, level, children, }) => {
|
|
6
7
|
const [X] = useState(getCustomMDXComponent);
|
|
7
8
|
const HeadingComponents = useMemo(() => {
|
|
8
9
|
return [null, X.h1, X.h2, X.h3, X.h4, X.h5, X.h6];
|
|
9
10
|
}, [X]);
|
|
10
11
|
const HeadingComponent = HeadingComponents[level];
|
|
11
|
-
const id = useMemo(() =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
12
|
+
const id = useMemo(() => [
|
|
13
|
+
uid,
|
|
14
|
+
slug ||
|
|
15
|
+
slugger?.slug(Children.toArray(children)
|
|
16
|
+
.filter((it) => typeof it === 'string')
|
|
17
|
+
.join('')),
|
|
18
|
+
]
|
|
19
|
+
.filter(Boolean)
|
|
20
|
+
.join('-') || undefined, [slug, uid, children]);
|
|
15
21
|
return (_jsxs(HeadingComponent, { id: id, children: [children, _jsx(X.a, { className: "header-anchor", href: `#${id}`, "aria-hidden": true, children: "#" })] }));
|
|
16
22
|
};
|