@alauda/doom 1.0.0-next.2 → 1.0.0-next.4
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/helpers.d.ts +1 -1
- package/lib/cli/helpers.js +1 -1
- package/lib/cli/index.js +4 -1
- package/lib/cli/load-config.d.ts +1 -1
- package/lib/cli/load-config.js +31 -10
- package/lib/cli/translate.js +3 -3
- package/lib/plugins/index.d.ts +2 -0
- package/lib/plugins/index.js +2 -0
- package/lib/plugins/sitemap/index.d.ts +16 -0
- package/lib/plugins/sitemap/index.js +51 -0
- 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/lib/runtime/components/_Markdown.js +1 -3
- package/lib/runtime/hooks/useTranslation.d.ts +1 -1
- package/lib/theme.d.ts +3 -0
- package/lib/theme.js +25 -0
- package/lib/types.d.ts +9 -0
- package/package.json +6 -3
package/lib/cli/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const parseBoolean: (value
|
|
1
|
+
export declare const parseBoolean: (value?: string) => boolean;
|
|
2
2
|
export declare const getMatchedDocFilePaths: (matched: string[]) => Promise<(string | string[])[]>;
|
|
3
3
|
/**
|
|
4
4
|
* Support custom id like `#hello world {#custom-id}`
|
package/lib/cli/helpers.js
CHANGED
|
@@ -3,7 +3,7 @@ import { glob } from 'tinyglobby';
|
|
|
3
3
|
import { xfetch } from 'x-fetch';
|
|
4
4
|
import { parse } from 'yaml';
|
|
5
5
|
import { FALSY_VALUES } from '../shared/index.js';
|
|
6
|
-
export const parseBoolean = (value) =>
|
|
6
|
+
export const parseBoolean = (value) => value === undefined || !FALSY_VALUES.has(value);
|
|
7
7
|
const DOC_PATTERN = /\.mdx?$/;
|
|
8
8
|
const isDoc = (filename) => DOC_PATTERN.test(filename);
|
|
9
9
|
export const getMatchedDocFilePaths = (matched) => Promise.all(matched.map(async (it) => {
|
package/lib/cli/index.js
CHANGED
|
@@ -43,7 +43,10 @@ program
|
|
|
43
43
|
.option('-E, --exclude <language...>', 'Include all languages except the specific language(s), `ru` for example')
|
|
44
44
|
.option('-o, --out-dir <path>', 'Override the `outDir` defined in the config file or the default `dist/{base}/{version}`, the resulting path will be `dist/{outDir}/{version}`')
|
|
45
45
|
.option('-r, --redirect <enum>', 'Whether to redirect to the locale closest to `navigator.language` when the user visits the site, could be `auto`, `never` or `only-default-lang`', 'only-default-lang')
|
|
46
|
-
.option('-R, --edit-repo [boolean|url]', 'Whether to enable or override the `editRepoBaseUrl` config feature, `https://github.com/` prefix could be omitted', (value) =>
|
|
46
|
+
.option('-R, --edit-repo [boolean|url]', 'Whether to enable or override the `editRepoBaseUrl` config feature, `https://github.com/` prefix could be omitted', (value) => value === undefined ||
|
|
47
|
+
(FALSY_VALUES.has(value) ? false : TRUTHY_VALUES.has(value) || value), false)
|
|
48
|
+
.option('-a, --algolia', 'Whether to enable Algolia search', parseBoolean, false)
|
|
49
|
+
.option('-S, --site-url', 'Whether to enable the siteUrl for sitemap generation', parseBoolean, false)
|
|
47
50
|
.option('-n, --no-open [boolean]', 'Do not open the browser after starting the server')
|
|
48
51
|
.command('dev', { isDefault: true })
|
|
49
52
|
.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, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, editRepo, }?: GlobalCliOptions): Promise<{
|
|
3
|
+
export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, editRepo, algolia, siteUrl, }?: GlobalCliOptions): Promise<{
|
|
4
4
|
config: UserConfig;
|
|
5
5
|
filepath?: string;
|
|
6
6
|
}>;
|
package/lib/cli/load-config.js
CHANGED
|
@@ -4,13 +4,14 @@ import { nodeTypes } from '@mdx-js/mdx';
|
|
|
4
4
|
import { pluginSass } from '@rsbuild/plugin-sass';
|
|
5
5
|
import { pluginYaml } from '@rsbuild/plugin-yaml';
|
|
6
6
|
import { addLeadingSlash, addTrailingSlash, normalizeSlash, removeLeadingSlash, } from '@rspress/core';
|
|
7
|
+
import { pluginAlgolia } from '@rspress/plugin-algolia';
|
|
8
|
+
import { pluginLlms } from '@rspress/plugin-llms';
|
|
7
9
|
import { logger } from '@rspress/shared/logger';
|
|
8
10
|
import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
|
|
9
11
|
import { difference } from 'es-toolkit';
|
|
10
12
|
import rehypeRaw from 'rehype-raw';
|
|
11
13
|
import { cyan } from 'yoctocolors';
|
|
12
|
-
import { autoTocPlugin } from '../plugins/
|
|
13
|
-
import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, rehypeFix, replacePlugin, } from '../plugins/index.js';
|
|
14
|
+
import { apiPlugin, autoSidebarPlugin, autoTocPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, rehypeFix, replacePlugin, sitemapPlugin, } from '../plugins/index.js';
|
|
14
15
|
import { isExplicitlyUnversioned, UNVERSIONED, } from '../shared/index.js';
|
|
15
16
|
import { pathExists, pkgResolve, resolveStaticConfig } from '../utils/index.js';
|
|
16
17
|
import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
|
|
@@ -48,7 +49,7 @@ const KNOWN_LOCALE_CONFIGS = {
|
|
|
48
49
|
},
|
|
49
50
|
},
|
|
50
51
|
};
|
|
51
|
-
const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, include, exclude, redirect, editRepo, }) => {
|
|
52
|
+
const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, include, exclude, redirect, editRepo, algolia, siteUrl, }) => {
|
|
52
53
|
const fallbackToZh = 'lang' in config && !config.lang;
|
|
53
54
|
root = resolveDocRoot(CWD, root, config.root);
|
|
54
55
|
const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
|
|
@@ -105,6 +106,7 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
|
|
|
105
106
|
}
|
|
106
107
|
const unusedLanguages = difference(allLanguages, locales.map(({ lang }) => lang));
|
|
107
108
|
const { editLink, ...zhLocale } = KNOWN_LOCALE_CONFIGS.zh;
|
|
109
|
+
const algoliaOptions = algolia ? config.algolia : undefined;
|
|
108
110
|
return {
|
|
109
111
|
userBase,
|
|
110
112
|
root,
|
|
@@ -158,6 +160,8 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
|
|
|
158
160
|
: { locales }),
|
|
159
161
|
},
|
|
160
162
|
plugins: [
|
|
163
|
+
algoliaOptions && pluginAlgolia(),
|
|
164
|
+
pluginLlms(),
|
|
161
165
|
apiPlugin({
|
|
162
166
|
localBasePath,
|
|
163
167
|
}),
|
|
@@ -174,7 +178,13 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
|
|
|
174
178
|
localBasePath,
|
|
175
179
|
force,
|
|
176
180
|
}),
|
|
177
|
-
|
|
181
|
+
siteUrl &&
|
|
182
|
+
config.siteUrl &&
|
|
183
|
+
sitemapPlugin({
|
|
184
|
+
domain: config.siteUrl,
|
|
185
|
+
}),
|
|
186
|
+
].filter(Boolean),
|
|
187
|
+
search: algoliaOptions ? false : undefined,
|
|
178
188
|
builderConfig: {
|
|
179
189
|
dev: {
|
|
180
190
|
lazyCompilation: lazy,
|
|
@@ -184,12 +194,21 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
|
|
|
184
194
|
open,
|
|
185
195
|
},
|
|
186
196
|
tools: {
|
|
187
|
-
rspack
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
rspack(rspackConfig, { mergeConfig, rspack }) {
|
|
198
|
+
return mergeConfig(rspackConfig, {
|
|
199
|
+
resolve: {
|
|
200
|
+
extensionAlias: {
|
|
201
|
+
'.js': ['.ts', '.tsx', '.js'],
|
|
202
|
+
},
|
|
191
203
|
},
|
|
192
|
-
|
|
204
|
+
plugins: [
|
|
205
|
+
new rspack.DefinePlugin({
|
|
206
|
+
'process.env.ALGOLIA_APP_ID': JSON.stringify(algoliaOptions?.appId),
|
|
207
|
+
'process.env.ALGOLIA_API_KEY': JSON.stringify(algoliaOptions?.apiKey),
|
|
208
|
+
'process.env.ALGOLIA_INDEX_NAME': JSON.stringify(algoliaOptions?.indexName),
|
|
209
|
+
}),
|
|
210
|
+
],
|
|
211
|
+
});
|
|
193
212
|
},
|
|
194
213
|
},
|
|
195
214
|
},
|
|
@@ -202,7 +221,7 @@ const findConfig = async (basePath) => {
|
|
|
202
221
|
}
|
|
203
222
|
}
|
|
204
223
|
};
|
|
205
|
-
export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, editRepo, } = {}) {
|
|
224
|
+
export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, editRepo, algolia, siteUrl, } = {}) {
|
|
206
225
|
let configFilePath;
|
|
207
226
|
if (configFile) {
|
|
208
227
|
configFilePath = path.resolve(configFile);
|
|
@@ -268,6 +287,8 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
|
|
|
268
287
|
exclude,
|
|
269
288
|
redirect,
|
|
270
289
|
editRepo,
|
|
290
|
+
algolia,
|
|
291
|
+
siteUrl,
|
|
271
292
|
});
|
|
272
293
|
base = commonConfig.base;
|
|
273
294
|
const mergedConfig = mergeRsbuildConfig(commonConfig, config, {
|
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
|
|
|
@@ -106,7 +106,7 @@ export const translate = async ({ source, sourceContent, target, targetContent =
|
|
|
106
106
|
},
|
|
107
107
|
],
|
|
108
108
|
model: 'gpt-4o-mini',
|
|
109
|
-
temperature: 0,
|
|
109
|
+
temperature: 0.2,
|
|
110
110
|
});
|
|
111
111
|
const { content, refusal } = choices[0].message;
|
|
112
112
|
if (refusal) {
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from './api/index.js';
|
|
2
2
|
export * from './auto-sidebar/index.js';
|
|
3
|
+
export * from './auto-toc/index.js';
|
|
3
4
|
export * from './directives/index.js';
|
|
4
5
|
export * from './global/index.js';
|
|
5
6
|
export * from './mermaid/index.js';
|
|
6
7
|
export * from './permission/index.js';
|
|
7
8
|
export * from './replace/index.js';
|
|
8
9
|
export * from './shiki/index.js';
|
|
10
|
+
export * from './sitemap/index.js';
|
package/lib/plugins/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from './api/index.js';
|
|
2
2
|
export * from './auto-sidebar/index.js';
|
|
3
|
+
export * from './auto-toc/index.js';
|
|
3
4
|
export * from './directives/index.js';
|
|
4
5
|
export * from './global/index.js';
|
|
5
6
|
export * from './mermaid/index.js';
|
|
6
7
|
export * from './permission/index.js';
|
|
7
8
|
export * from './replace/index.js';
|
|
8
9
|
export * from './shiki/index.js';
|
|
10
|
+
export * from './sitemap/index.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RspressPlugin } from '@rspress/shared';
|
|
2
|
+
export type ChangeFreq = 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
|
|
3
|
+
export type Priority = '0.0' | '0.1' | '0.2' | '0.3' | '0.4' | '0.5' | '0.6' | '0.7' | '0.8' | '0.9' | '1.0';
|
|
4
|
+
export interface Sitemap {
|
|
5
|
+
loc: string;
|
|
6
|
+
lastmod?: string;
|
|
7
|
+
changefreq?: ChangeFreq;
|
|
8
|
+
priority?: Priority;
|
|
9
|
+
}
|
|
10
|
+
export interface Options {
|
|
11
|
+
domain?: string;
|
|
12
|
+
customMaps?: Record<string, Sitemap>;
|
|
13
|
+
defaultPriority?: Priority;
|
|
14
|
+
defaultChangeFreq?: ChangeFreq;
|
|
15
|
+
}
|
|
16
|
+
export declare function sitemapPlugin(options?: Options): RspressPlugin;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// based on https://github.com/jl917/rspress-plugin-sitemap/blob/master/src/index.ts
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { logger } from '@rspress/shared/logger';
|
|
5
|
+
const generateNode = (sitemap) => {
|
|
6
|
+
let result = '<url>';
|
|
7
|
+
for (const [tag, value] of Object.entries(sitemap)) {
|
|
8
|
+
result += `<${tag}>${value}</${tag}>`;
|
|
9
|
+
}
|
|
10
|
+
result += '</url>';
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
const generateXml = (sitemaps) => {
|
|
14
|
+
logger.log(`Generate sitemap.xml for ${sitemaps.length} pages.`);
|
|
15
|
+
return `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${sitemaps.reduce((node, sitemap) => node + generateNode(sitemap), '')}</urlset>`;
|
|
16
|
+
};
|
|
17
|
+
export function sitemapPlugin(options) {
|
|
18
|
+
options = {
|
|
19
|
+
domain: 'https://rspress.dev',
|
|
20
|
+
customMaps: {},
|
|
21
|
+
defaultChangeFreq: 'monthly',
|
|
22
|
+
defaultPriority: '0.5',
|
|
23
|
+
...options,
|
|
24
|
+
};
|
|
25
|
+
const sitemaps = [];
|
|
26
|
+
const set = new Set();
|
|
27
|
+
return {
|
|
28
|
+
name: 'rspress-plugin-sitemap',
|
|
29
|
+
extendPageData(pageData, isProd) {
|
|
30
|
+
if (!isProd || set.has(pageData.id)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
set.add(pageData.id);
|
|
34
|
+
sitemaps.push({
|
|
35
|
+
loc: `${options.domain}${pageData.routePath}`,
|
|
36
|
+
lastmod: fs.statSync(pageData._filepath).mtime.toISOString(),
|
|
37
|
+
priority: pageData.routePath === '/' ? '1.0' : options.defaultPriority,
|
|
38
|
+
changefreq: options.defaultChangeFreq,
|
|
39
|
+
...options.customMaps?.[pageData.routePath],
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
afterBuild(config, isProd) {
|
|
43
|
+
if (!isProd) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const outputPath = `${config.outDir || 'doc_build'}/sitemap.xml`;
|
|
47
|
+
fs.mkdirSync(dirname(outputPath), { recursive: true });
|
|
48
|
+
fs.writeFileSync(outputPath, generateXml(sitemaps));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -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 } from 'react';
|
|
8
|
+
import { Fragment, useId, useMemo } 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';
|
|
@@ -91,6 +91,7 @@ const getRefsForPath = (openapi, path, knownRefs) => {
|
|
|
91
91
|
export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathPrefix_, }) => {
|
|
92
92
|
const { page } = usePageData();
|
|
93
93
|
const pathPrefix = pathPrefix_ ?? (virtual.pathPrefix || '');
|
|
94
|
+
const uid = useId();
|
|
94
95
|
const slugger = useMemo(() => new BananaSlug(), []);
|
|
95
96
|
const [pathItem, openapi, openapiPath, refs] = useMemo(() => {
|
|
96
97
|
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
@@ -113,7 +114,7 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
113
114
|
console.error(`No OpenAPI path definition found for ${path}`);
|
|
114
115
|
return null;
|
|
115
116
|
}
|
|
116
|
-
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) => {
|
|
117
|
+
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) => {
|
|
117
118
|
if (!pathItem[method]) {
|
|
118
119
|
return null;
|
|
119
120
|
}
|
|
@@ -125,9 +126,9 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
125
126
|
const requestBodySchema = requestBodyRef
|
|
126
127
|
? resolveRef(openapi, requestBodyRef)
|
|
127
128
|
: undefined;
|
|
128
|
-
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));
|
|
129
|
+
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));
|
|
129
130
|
}), refs?.map((ref) => {
|
|
130
|
-
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, collectRefs: false }, ref));
|
|
131
|
+
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, uid: uid, collectRefs: false }, ref));
|
|
131
132
|
})] }));
|
|
132
133
|
};
|
|
133
134
|
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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { usePageData } from '@rspress/core/runtime';
|
|
3
3
|
import openapisMap from 'doom-@api-openapisMap';
|
|
4
|
-
import { useMemo } from 'react';
|
|
4
|
+
import { useId, useMemo } from 'react';
|
|
5
5
|
import { modelName, omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
6
6
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
7
7
|
import { Markdown } from './_Markdown.js';
|
|
@@ -68,8 +68,12 @@ const getRefsForSchema = (openapi, schema, knownRefs) => {
|
|
|
68
68
|
collectRefs(refSchema);
|
|
69
69
|
return Array.from(refs);
|
|
70
70
|
};
|
|
71
|
-
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, collectRefs = true, }) => {
|
|
71
|
+
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, uid, collectRefs = true, }) => {
|
|
72
72
|
const { page } = usePageData();
|
|
73
|
+
const innerUid = useId();
|
|
74
|
+
if (uid == null) {
|
|
75
|
+
uid = innerUid;
|
|
76
|
+
}
|
|
73
77
|
const [schemaItem, openapi, openapiPath] = useMemo(() => {
|
|
74
78
|
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
75
79
|
if (openapiPath_ && pathname !== openapiPath_) {
|
|
@@ -91,6 +95,6 @@ export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, collectRefs = tr
|
|
|
91
95
|
return getRefsForSchema(openapi, schema, omitRoutePathRefs(page.routePath));
|
|
92
96
|
}
|
|
93
97
|
}, [collectRefs, openapi, page.routePath, schema]);
|
|
94
|
-
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)))] }));
|
|
98
|
+
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)))] }));
|
|
95
99
|
};
|
|
96
100
|
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,14 +2,20 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import BananaSlug from 'github-slugger';
|
|
3
3
|
import { Children, useMemo } from 'react';
|
|
4
4
|
import { X } from './_X.js';
|
|
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 HeadingComponents = useMemo(() => {
|
|
7
8
|
return [null, X.h1, X.h2, X.h3, X.h4, X.h5, X.h6];
|
|
8
9
|
}, [X]);
|
|
9
10
|
const HeadingComponent = HeadingComponents[level];
|
|
10
|
-
const id = useMemo(() =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.
|
|
11
|
+
const id = useMemo(() => [
|
|
12
|
+
uid,
|
|
13
|
+
slug ||
|
|
14
|
+
slugger?.slug(Children.toArray(children)
|
|
15
|
+
.filter((it) => typeof it === 'string')
|
|
16
|
+
.join('')),
|
|
17
|
+
]
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
.join('-') || undefined, [slug, uid, children]);
|
|
14
20
|
return (_jsxs(HeadingComponent, { id: id, children: [children, _jsx(X.a, { className: "header-anchor", href: `#${id}`, "aria-hidden": true, children: "#" })] }));
|
|
15
21
|
};
|
|
@@ -3,6 +3,4 @@ import {} from 'react';
|
|
|
3
3
|
import ReactMarkdown from 'react-markdown';
|
|
4
4
|
import remarkGfm from 'remark-gfm';
|
|
5
5
|
import { X } from './_X.js';
|
|
6
|
-
export const Markdown = ({ children }) => {
|
|
7
|
-
return (children && (_jsx(ReactMarkdown, { remarkPlugins: [[remarkGfm]], components: X, skipHtml: true, children: children })));
|
|
8
|
-
};
|
|
6
|
+
export const Markdown = ({ children }) => children && (_jsx(ReactMarkdown, { remarkPlugins: [[remarkGfm]], components: X, skipHtml: true, children: children }));
|
|
@@ -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" | "
|
|
3
|
+
export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "toc" | "create" | "update" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf") => string;
|
package/lib/theme.d.ts
ADDED
package/lib/theme.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useLang } from '@rspress/core/runtime';
|
|
3
|
+
import { Search as OriginalSearch } from '@rspress/core/theme';
|
|
4
|
+
import { Search as AlgoliaSearch, ZH_LOCALES, } from '@rspress/plugin-algolia/runtime';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
const Search = process.env.ALGOLIA_APP_ID &&
|
|
7
|
+
process.env.ALGOLIA_API_KEY &&
|
|
8
|
+
process.env.ALGOLIA_INDEX_NAME
|
|
9
|
+
? () => {
|
|
10
|
+
const lang = useLang();
|
|
11
|
+
const docSearchProps = useMemo(() => ({
|
|
12
|
+
appId: process.env.ALGOLIA_APP_ID,
|
|
13
|
+
apiKey: process.env.ALGOLIA_API_KEY,
|
|
14
|
+
indexName: process.env.ALGOLIA_INDEX_NAME,
|
|
15
|
+
searchParameters: {
|
|
16
|
+
facetFilters: [`lang:${lang}`],
|
|
17
|
+
},
|
|
18
|
+
}), [lang]);
|
|
19
|
+
return (_jsx(AlgoliaSearch, { docSearchProps: docSearchProps, locales: ZH_LOCALES }));
|
|
20
|
+
}
|
|
21
|
+
: OriginalSearch;
|
|
22
|
+
// eslint-disable-next-line import-x/export
|
|
23
|
+
export * from '@rspress/core/theme';
|
|
24
|
+
// eslint-disable-next-line import-x/export
|
|
25
|
+
export { Search };
|
package/lib/types.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface GlobalCliOptions {
|
|
|
20
20
|
outDir?: string;
|
|
21
21
|
redirect?: 'auto' | 'never' | 'only-default-lang';
|
|
22
22
|
editRepo?: boolean | string;
|
|
23
|
+
algolia?: boolean;
|
|
24
|
+
siteUrl?: boolean;
|
|
23
25
|
}
|
|
24
26
|
export interface TranslateOptions {
|
|
25
27
|
systemPrompt?: string;
|
|
@@ -28,6 +30,11 @@ export interface TranslateOptions {
|
|
|
28
30
|
export interface LintOptions {
|
|
29
31
|
cspellOptions?: Partial<Options>;
|
|
30
32
|
}
|
|
33
|
+
export interface AlgoliaOptions {
|
|
34
|
+
appId: string;
|
|
35
|
+
apiKey: string;
|
|
36
|
+
indexName: string;
|
|
37
|
+
}
|
|
31
38
|
declare module '@rspress/shared' {
|
|
32
39
|
interface UserConfig {
|
|
33
40
|
prefix?: string;
|
|
@@ -43,6 +50,8 @@ declare module '@rspress/shared' {
|
|
|
43
50
|
translate?: TranslateOptions;
|
|
44
51
|
editRepoBaseUrl?: string;
|
|
45
52
|
lint?: LintOptions;
|
|
53
|
+
algolia?: AlgoliaOptions;
|
|
54
|
+
siteUrl?: string;
|
|
46
55
|
}
|
|
47
56
|
interface SiteData {
|
|
48
57
|
originalTitle?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": "git+https://github.com/alauda/doom.git",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"./package.json": "./package.json",
|
|
15
15
|
"./config": "./lib/config.js",
|
|
16
16
|
"./runtime": "./lib/runtime/index.js",
|
|
17
|
+
"./theme": "./lib/theme.js",
|
|
17
18
|
"./types": "./lib/types.js"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
@@ -41,11 +42,13 @@
|
|
|
41
42
|
"@rsbuild/plugin-sass": "^1.3.1",
|
|
42
43
|
"@rsbuild/plugin-yaml": "^1.0.2",
|
|
43
44
|
"@rspress/core": "2.0.0-beta.8",
|
|
45
|
+
"@rspress/plugin-algolia": "2.0.0-beta.8",
|
|
46
|
+
"@rspress/plugin-llms": "^2.0.0-beta.8",
|
|
44
47
|
"@shikijs/transformers": "^3.4.2",
|
|
45
48
|
"chokidar": "^4.0.3",
|
|
46
49
|
"cli-progress": "^3.12.0",
|
|
47
50
|
"clsx": "^2.1.1",
|
|
48
|
-
"commander": "^
|
|
51
|
+
"commander": "^13.1.0",
|
|
49
52
|
"ejs": "^3.1.10",
|
|
50
53
|
"es-toolkit": "^1.38.0",
|
|
51
54
|
"eslint": "^9.27.0",
|
|
@@ -73,7 +76,7 @@
|
|
|
73
76
|
"swagger2openapi": "^7.0.8",
|
|
74
77
|
"tinyglobby": "^0.2.14",
|
|
75
78
|
"type-fest": "^4.41.0",
|
|
76
|
-
"typescript-eslint": "^8.
|
|
79
|
+
"typescript-eslint": "^8.33.0",
|
|
77
80
|
"x-fetch": "^0.2.6",
|
|
78
81
|
"yaml": "^2.8.0",
|
|
79
82
|
"yoctocolors": "^2.1.1"
|