@alauda/doom 1.4.0 → 1.5.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/lib/cli/lint.js +2 -56
- package/lib/cli/load-config.d.ts +2 -2
- package/lib/cli/load-config.js +12 -7
- package/lib/cspell.d.ts +2 -0
- package/lib/cspell.js +67 -0
- package/lib/eslint.d.ts +5 -0
- package/lib/eslint.js +76 -0
- package/lib/plugins/sitemap/index.js +2 -2
- package/lib/runtime/components/OpenAPIPath.js +4 -3
- package/lib/runtime/components/OpenAPIRef.d.ts +12 -2
- package/lib/runtime/components/OpenAPIRef.js +8 -3
- package/lib/runtime/components/_HeadingTitle.d.ts +1 -2
- package/lib/runtime/components/_HeadingTitle.js +4 -2
- package/lib/runtime/components/_RefLink.js +5 -2
- package/lib/runtime/components/_context.d.ts +3 -0
- package/lib/runtime/components/_context.js +4 -0
- package/package.json +12 -9
package/lib/cli/lint.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import cspellRecommended from '@cspell/eslint-plugin/recommended';
|
|
2
|
-
import js from '@eslint/js';
|
|
3
|
-
import react from '@eslint-react/eslint-plugin';
|
|
4
1
|
import { logger } from '@rspress/shared/logger';
|
|
5
2
|
import { Command } from 'commander';
|
|
6
|
-
import { merge } from 'es-toolkit/compat';
|
|
7
3
|
import { ESLint } from 'eslint';
|
|
8
|
-
import
|
|
9
|
-
import tseslint from 'typescript-eslint';
|
|
10
|
-
import { parseTerms } from './helpers.js';
|
|
4
|
+
import doom from '../eslint.js';
|
|
11
5
|
import { loadConfig } from './load-config.js';
|
|
12
6
|
export const lintCommand = new Command('lint')
|
|
13
7
|
.description('Lint the documentation')
|
|
@@ -16,59 +10,11 @@ export const lintCommand = new Command('lint')
|
|
|
16
10
|
const globalOptions = this.optsWithGlobals();
|
|
17
11
|
const { config } = await loadConfig(root, globalOptions);
|
|
18
12
|
const docsDir = config.root;
|
|
19
|
-
const parsedTerms = await parseTerms();
|
|
20
13
|
const eslint = new ESLint({
|
|
21
14
|
cwd: docsDir,
|
|
22
15
|
overrideConfigFile: true,
|
|
23
16
|
// @ts-expect-error -- stronger types
|
|
24
|
-
overrideConfig:
|
|
25
|
-
{
|
|
26
|
-
extends: [
|
|
27
|
-
js.configs.recommended,
|
|
28
|
-
react.configs.recommended,
|
|
29
|
-
mdx.configs.flat,
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
files: ['**/en/**/*.{js,jsx,md,mdx,ts,tsx}'],
|
|
34
|
-
extends: [cspellRecommended],
|
|
35
|
-
rules: {
|
|
36
|
-
'@cspell/spellchecker': [
|
|
37
|
-
'error',
|
|
38
|
-
merge({
|
|
39
|
-
autoFix: true,
|
|
40
|
-
cspell: {
|
|
41
|
-
allowCompoundWords: true,
|
|
42
|
-
words: parsedTerms.map((it) => it.en),
|
|
43
|
-
flagWords: parsedTerms.flatMap(({ badCases }) => badCases?.en ?? []),
|
|
44
|
-
},
|
|
45
|
-
}, config.lint?.cspellOptions),
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
files: ['**/*.{ts,tsx}'],
|
|
51
|
-
extends: [
|
|
52
|
-
tseslint.configs.recommendedTypeChecked,
|
|
53
|
-
react.configs['recommended-typescript'],
|
|
54
|
-
],
|
|
55
|
-
rules: {
|
|
56
|
-
'@typescript-eslint/no-misused-promises': 'off',
|
|
57
|
-
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
58
|
-
'@typescript-eslint/restrict-template-expressions': [
|
|
59
|
-
'error',
|
|
60
|
-
{ allowNumber: true },
|
|
61
|
-
],
|
|
62
|
-
'prefer-const': ['error', { destructuring: 'all' }],
|
|
63
|
-
},
|
|
64
|
-
languageOptions: {
|
|
65
|
-
parser: tseslint.parser,
|
|
66
|
-
parserOptions: {
|
|
67
|
-
projectService: true,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
]),
|
|
17
|
+
overrideConfig: await doom(config.lint?.cspellOptions),
|
|
72
18
|
});
|
|
73
19
|
logger.start('Linting...');
|
|
74
20
|
const results = await eslint.lintFiles('**/*.{js,jsx,ts,tsx,md,mdx}');
|
package/lib/cli/load-config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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, algolia, siteUrl, }?: GlobalCliOptions): Promise<{
|
|
3
|
+
export declare function loadConfig(root?: string | URL, { 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
|
}>;
|
|
7
|
-
export declare function resolveDocRoot(
|
|
7
|
+
export declare function resolveDocRoot(cliRoot?: string, configRoot?: string): string;
|
package/lib/cli/load-config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
3
4
|
import { pluginReact } from '@rsbuild/plugin-react';
|
|
4
5
|
import { pluginSass } from '@rsbuild/plugin-sass';
|
|
5
6
|
import { pluginSvgr } from '@rsbuild/plugin-svgr';
|
|
@@ -14,7 +15,7 @@ import { cyan } from 'yoctocolors';
|
|
|
14
15
|
import { apiPlugin, autoSidebarPlugin, autoTocPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, replacePlugin, sitemapPlugin, } from '../plugins/index.js';
|
|
15
16
|
import { isExplicitlyUnversioned, UNVERSIONED, } from '../shared/index.js';
|
|
16
17
|
import { pathExists, pkgResolve, resolveStaticConfig } from '../utils/index.js';
|
|
17
|
-
import {
|
|
18
|
+
import { DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
|
|
18
19
|
import { defaultGitHubUrl } from './helpers.js';
|
|
19
20
|
const DEFAULT_LOGO = '/logo.svg';
|
|
20
21
|
const KNOWN_LOCALE_CONFIGS = {
|
|
@@ -61,7 +62,7 @@ const ALAUDA_RU_ALGOLIA_OPTIONS = {
|
|
|
61
62
|
};
|
|
62
63
|
const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, include, exclude, redirect, editRepo, algolia, siteUrl, }) => {
|
|
63
64
|
const fallbackToZh = 'lang' in config && !config.lang;
|
|
64
|
-
root = resolveDocRoot(
|
|
65
|
+
root = resolveDocRoot(root, config.root);
|
|
65
66
|
const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
|
|
66
67
|
const userBase = (base = addLeadingSlash(addTrailingSlash(base || config.base || '/')));
|
|
67
68
|
if (version && !isExplicitlyUnversioned(version)) {
|
|
@@ -246,6 +247,10 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
|
|
|
246
247
|
}
|
|
247
248
|
else {
|
|
248
249
|
if (root) {
|
|
250
|
+
root = root.toString();
|
|
251
|
+
if (root.startsWith('file:')) {
|
|
252
|
+
root = fileURLToPath(root);
|
|
253
|
+
}
|
|
249
254
|
configFilePath = await findConfig(path.resolve(root, DEFAULT_CONFIG_NAME));
|
|
250
255
|
}
|
|
251
256
|
if (!configFilePath) {
|
|
@@ -292,7 +297,7 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
|
|
|
292
297
|
const commonConfig = await getCommonConfig({
|
|
293
298
|
config,
|
|
294
299
|
configFilePath,
|
|
295
|
-
root,
|
|
300
|
+
root: root,
|
|
296
301
|
base,
|
|
297
302
|
version,
|
|
298
303
|
download,
|
|
@@ -353,15 +358,15 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
|
|
|
353
358
|
filepath: configFilePath,
|
|
354
359
|
};
|
|
355
360
|
}
|
|
356
|
-
export function resolveDocRoot(
|
|
361
|
+
export function resolveDocRoot(cliRoot, configRoot) {
|
|
357
362
|
// CLI root has highest priority
|
|
358
363
|
if (cliRoot) {
|
|
359
|
-
return path.
|
|
364
|
+
return path.resolve(cliRoot);
|
|
360
365
|
}
|
|
361
366
|
// Config root is next in priority
|
|
362
367
|
if (configRoot) {
|
|
363
|
-
return path.isAbsolute(configRoot) ? configRoot : path.
|
|
368
|
+
return path.isAbsolute(configRoot) ? configRoot : path.resolve(configRoot);
|
|
364
369
|
}
|
|
365
370
|
// Default to 'docs' if no root is specified
|
|
366
|
-
return path.
|
|
371
|
+
return path.resolve('docs');
|
|
367
372
|
}
|
package/lib/cspell.d.ts
ADDED
package/lib/cspell.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseTerms } from './cli/helpers.js';
|
|
4
|
+
const resolveDictionaries = async () => {
|
|
5
|
+
const dictionariesDir = path.resolve('.cspell');
|
|
6
|
+
try {
|
|
7
|
+
if (!(await fs.stat(dictionariesDir)).isDirectory()) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const dictionaries = [];
|
|
15
|
+
const dictionaryDefinitions = [];
|
|
16
|
+
for (const file of await fs.readdir(dictionariesDir, {
|
|
17
|
+
withFileTypes: true,
|
|
18
|
+
})) {
|
|
19
|
+
if (!file.isFile()) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const dictionary = path.parse(file.name).name;
|
|
23
|
+
dictionaries.push(dictionary);
|
|
24
|
+
dictionaryDefinitions.push({
|
|
25
|
+
name: dictionary,
|
|
26
|
+
path: `.cspell/${file.name}`,
|
|
27
|
+
addWords: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return { dictionaries, dictionaryDefinitions };
|
|
31
|
+
};
|
|
32
|
+
const CASE_SENSITIVE_DICTIONARY = '$$case-sensitive$$';
|
|
33
|
+
export default async function doom() {
|
|
34
|
+
const parsedTerms = await parseTerms();
|
|
35
|
+
const words = [];
|
|
36
|
+
const caseSensitiveWords = [];
|
|
37
|
+
const flagWords = parsedTerms.flatMap((it) => {
|
|
38
|
+
const word = it.en;
|
|
39
|
+
const badCases = it.badCases?.en ?? [];
|
|
40
|
+
if (badCases.some((c) => word !== c && word.toLowerCase() === c.toLowerCase())) {
|
|
41
|
+
caseSensitiveWords.push(it);
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
words.push(word);
|
|
45
|
+
return badCases.map((c) => `${c}->${word}`);
|
|
46
|
+
});
|
|
47
|
+
const { dictionaries = [], dictionaryDefinitions = [] } = (await resolveDictionaries()) ?? {};
|
|
48
|
+
if (caseSensitiveWords.length) {
|
|
49
|
+
dictionaries.push(CASE_SENSITIVE_DICTIONARY);
|
|
50
|
+
dictionaryDefinitions.push({
|
|
51
|
+
name: CASE_SENSITIVE_DICTIONARY,
|
|
52
|
+
words: caseSensitiveWords.flatMap((it) => [
|
|
53
|
+
it.en,
|
|
54
|
+
...(it.badCases?.en ?? []).map((c) => `!${c}`),
|
|
55
|
+
]),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
allowCompoundWords: true,
|
|
60
|
+
language: 'en,en-GB,en-US',
|
|
61
|
+
useGitignore: true,
|
|
62
|
+
words,
|
|
63
|
+
flagWords,
|
|
64
|
+
dictionaries,
|
|
65
|
+
dictionaryDefinitions,
|
|
66
|
+
};
|
|
67
|
+
}
|
package/lib/eslint.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Options } from '@cspell/eslint-plugin';
|
|
2
|
+
import tseslint from 'typescript-eslint';
|
|
3
|
+
declare function doom(cspellOptions?: Options): Promise<tseslint.ConfigArray>;
|
|
4
|
+
declare function doom(root: string | URL): Promise<tseslint.ConfigArray>;
|
|
5
|
+
export default doom;
|
package/lib/eslint.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import cspellRecommended from '@cspell/eslint-plugin/recommended';
|
|
2
|
+
import js from '@eslint/js';
|
|
3
|
+
import react from '@eslint-react/eslint-plugin';
|
|
4
|
+
import { merge } from 'es-toolkit/compat';
|
|
5
|
+
import * as mdx from 'eslint-plugin-mdx';
|
|
6
|
+
import globals from 'globals';
|
|
7
|
+
import tseslint from 'typescript-eslint';
|
|
8
|
+
import { loadConfig } from './cli/load-config.js';
|
|
9
|
+
async function doom(cspellOptionsOrRoot) {
|
|
10
|
+
let cspellOptions;
|
|
11
|
+
if (typeof cspellOptionsOrRoot === 'string' ||
|
|
12
|
+
cspellOptionsOrRoot instanceof URL) {
|
|
13
|
+
const { config } = await loadConfig(cspellOptionsOrRoot);
|
|
14
|
+
cspellOptions = config.lint?.cspellOptions;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
cspellOptions = cspellOptionsOrRoot;
|
|
18
|
+
}
|
|
19
|
+
return tseslint.config([
|
|
20
|
+
{
|
|
21
|
+
ignores: ['**/.yarn', '**/dist', '**/lib', '**/node_modules'],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
extends: [
|
|
25
|
+
js.configs.recommended,
|
|
26
|
+
react.configs.recommended,
|
|
27
|
+
mdx.configs.flat,
|
|
28
|
+
],
|
|
29
|
+
languageOptions: {
|
|
30
|
+
globals: globals.node,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
files: ['**/en/**/*.{js,jsx,md,mdx,ts,tsx}'],
|
|
35
|
+
extends: [cspellRecommended],
|
|
36
|
+
languageOptions: {
|
|
37
|
+
globals: globals.browser,
|
|
38
|
+
},
|
|
39
|
+
rules: {
|
|
40
|
+
'@cspell/spellchecker': [
|
|
41
|
+
'error',
|
|
42
|
+
merge({ autoFix: true }, cspellOptions),
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
files: ['**/*.mdx'],
|
|
48
|
+
rules: {
|
|
49
|
+
'no-unused-expressions': 'off',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
files: ['**/*.{ts,tsx}'],
|
|
54
|
+
extends: [
|
|
55
|
+
tseslint.configs.recommendedTypeChecked,
|
|
56
|
+
react.configs['recommended-typescript'],
|
|
57
|
+
],
|
|
58
|
+
rules: {
|
|
59
|
+
'@typescript-eslint/no-misused-promises': 'off',
|
|
60
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
61
|
+
'@typescript-eslint/restrict-template-expressions': [
|
|
62
|
+
'error',
|
|
63
|
+
{ allowNumber: true },
|
|
64
|
+
],
|
|
65
|
+
'prefer-const': ['error', { destructuring: 'all' }],
|
|
66
|
+
},
|
|
67
|
+
languageOptions: {
|
|
68
|
+
parser: tseslint.parser,
|
|
69
|
+
parserOptions: {
|
|
70
|
+
projectService: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
export default doom;
|
|
@@ -27,10 +27,10 @@ export function sitemapPlugin(options) {
|
|
|
27
27
|
return {
|
|
28
28
|
name: 'rspress-plugin-sitemap',
|
|
29
29
|
extendPageData(pageData, isProd) {
|
|
30
|
-
if (!isProd || set.has(pageData.
|
|
30
|
+
if (!isProd || set.has(pageData.routePath)) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
set.add(pageData.
|
|
33
|
+
set.add(pageData.routePath);
|
|
34
34
|
sitemaps.push({
|
|
35
35
|
loc: `${options.domain}${pageData.routePath}`,
|
|
36
36
|
lastmod: fs.statSync(pageData._filepath).mtime.toISOString(),
|
|
@@ -12,6 +12,7 @@ import { OpenAPIProperties, OpenAPIProperty, OpenAPIRef } from './OpenAPIRef.js'
|
|
|
12
12
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
13
13
|
import { RefLink } from './_RefLink.js';
|
|
14
14
|
import { X } from './_X.js';
|
|
15
|
+
import { UidProvider } from './_context.js';
|
|
15
16
|
export const OpenAPIParameters = ({ parameters, openapi, }) => {
|
|
16
17
|
return (_jsx(X.ul, { children: parameters.map((param, index) => {
|
|
17
18
|
const paramObj = '$ref' in param
|
|
@@ -116,7 +117,7 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
116
117
|
console.error(`No OpenAPI path definition found for ${path}`);
|
|
117
118
|
return null;
|
|
118
119
|
}
|
|
119
|
-
return (_jsxs(
|
|
120
|
+
return (_jsxs(UidProvider, { value: uid, 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) => {
|
|
120
121
|
if (!pathItem[method]) {
|
|
121
122
|
return null;
|
|
122
123
|
}
|
|
@@ -128,9 +129,9 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
128
129
|
const requestBodySchema = requestBodyRef
|
|
129
130
|
? resolveRef(openapi, requestBodyRef)
|
|
130
131
|
: undefined;
|
|
131
|
-
return (_jsxs(Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger,
|
|
132
|
+
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));
|
|
132
133
|
}), refs?.map((ref) => {
|
|
133
|
-
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath,
|
|
134
|
+
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, isCommonRef: false, collectRefs: false }, ref));
|
|
134
135
|
})] }));
|
|
135
136
|
};
|
|
136
137
|
export default OpenAPIPath;
|
|
@@ -8,7 +8,17 @@ 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
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Whether is a common reference, no `uid` will be generated.
|
|
13
|
+
*
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
isCommonRef?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to collect references from the schema.
|
|
19
|
+
*
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
12
22
|
collectRefs?: boolean;
|
|
13
23
|
}
|
|
14
24
|
export declare const OpenAPIProperty: ({ name, property, openapi, }: {
|
|
@@ -20,5 +30,5 @@ export declare const OpenAPIProperties: ({ properties, openapi, }: {
|
|
|
20
30
|
properties: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject>;
|
|
21
31
|
openapi: OpenAPIV3_1.Document;
|
|
22
32
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
-
export declare const OpenAPIRef: ({ schema, openapiPath: openapiPath_,
|
|
33
|
+
export declare const OpenAPIRef: ({ schema, openapiPath: openapiPath_, isCommonRef, collectRefs, }: OpenAPIRefProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
24
34
|
export default OpenAPIRef;
|
|
@@ -7,6 +7,7 @@ import { Markdown } from './Markdown.js';
|
|
|
7
7
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
8
8
|
import { RefLink } from './_RefLink.js';
|
|
9
9
|
import { X } from './_X.js';
|
|
10
|
+
import { UidProvider, useUid } from './_context.js';
|
|
10
11
|
export const OpenAPIProperty = ({ name, property, openapi, }) => {
|
|
11
12
|
const propObj = '$ref' in property ? resolveRef(openapi, property.$ref) : property;
|
|
12
13
|
const type = propObj.type;
|
|
@@ -68,10 +69,14 @@ const getRefsForSchema = (openapi, schema, knownRefs) => {
|
|
|
68
69
|
collectRefs(refSchema);
|
|
69
70
|
return Array.from(refs);
|
|
70
71
|
};
|
|
71
|
-
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_,
|
|
72
|
+
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, isCommonRef = true, collectRefs = true, }) => {
|
|
72
73
|
const { page } = usePageData();
|
|
74
|
+
let uid = useUid();
|
|
73
75
|
const innerUid = useId();
|
|
74
|
-
if (
|
|
76
|
+
if (isCommonRef) {
|
|
77
|
+
uid = ''; // common references do not need a unique ID
|
|
78
|
+
}
|
|
79
|
+
else if (!uid) {
|
|
75
80
|
uid = innerUid;
|
|
76
81
|
}
|
|
77
82
|
const [schemaItem, openapi, openapiPath] = useMemo(() => {
|
|
@@ -95,6 +100,6 @@ export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, uid, collectRefs
|
|
|
95
100
|
console.error(`No OpenAPI schema definition found for ${schema}\n`);
|
|
96
101
|
return null;
|
|
97
102
|
}
|
|
98
|
-
return (_jsxs(
|
|
103
|
+
return (_jsxs(UidProvider, { value: uid, 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, isCommonRef: isCommonRef, collectRefs: false }, schema)))] }));
|
|
99
104
|
};
|
|
100
105
|
export default OpenAPIRef;
|
|
@@ -3,8 +3,7 @@ import { type ReactNode } from 'react';
|
|
|
3
3
|
export interface HeadingTitleProps {
|
|
4
4
|
slug?: string;
|
|
5
5
|
slugger?: BananaSlug;
|
|
6
|
-
uid?: string;
|
|
7
6
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
8
7
|
children: ReactNode;
|
|
9
8
|
}
|
|
10
|
-
export declare const HeadingTitle: ({ slug, slugger,
|
|
9
|
+
export declare const HeadingTitle: ({ slug, slugger, level, children, }: HeadingTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,8 +2,10 @@ 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
|
-
|
|
6
|
-
|
|
5
|
+
import { useUid } from './_context.js';
|
|
6
|
+
// TODO: use context to simplify the usage of `slugger`
|
|
7
|
+
export const HeadingTitle = ({ slug, slugger, level, children, }) => {
|
|
8
|
+
const uid = useUid();
|
|
7
9
|
const HeadingComponents = useMemo(() => {
|
|
8
10
|
return [null, X.h1, X.h2, X.h3, X.h4, X.h5, X.h6];
|
|
9
11
|
}, []);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { COMMON_REFS, modelName } from '../utils.js';
|
|
3
3
|
import { X } from './_X.js';
|
|
4
|
+
import { useUid } from './_context.js';
|
|
4
5
|
export const RefLink = ({ $ref }) => {
|
|
6
|
+
const uid = useUid();
|
|
5
7
|
if (!$ref) {
|
|
6
8
|
return null;
|
|
7
9
|
}
|
|
8
10
|
const ref = $ref.replace('/components/schemas/', '');
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
+
const plainRef = ref.slice(1);
|
|
12
|
+
const refName = modelName(plainRef);
|
|
13
|
+
return (_jsx(X.a, { href: COMMON_REFS[plainRef] || (uid ? `#${uid}-${plainRef}` : ref), children: refName }));
|
|
11
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": "git+https://github.com/alauda/doom.git",
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
"./package.json": "./package.json",
|
|
15
15
|
"./config": "./lib/config.js",
|
|
16
|
+
"./cspell": "./lib/cspell.js",
|
|
17
|
+
"./eslint": "./lib/eslint.js",
|
|
16
18
|
"./runtime": "./lib/runtime/index.js",
|
|
17
19
|
"./theme": "./lib/theme.js",
|
|
18
20
|
"./types": "./lib/types.js"
|
|
@@ -34,11 +36,11 @@
|
|
|
34
36
|
"rspress-plugins"
|
|
35
37
|
],
|
|
36
38
|
"dependencies": {
|
|
37
|
-
"@cspell/eslint-plugin": "^8.19.4 || ^9.
|
|
38
|
-
"@eslint-react/eslint-plugin": "^1.52.
|
|
39
|
+
"@cspell/eslint-plugin": "^8.19.4 || ^9.1.1",
|
|
40
|
+
"@eslint-react/eslint-plugin": "^1.52.2",
|
|
39
41
|
"@inquirer/prompts": "^7.5.3",
|
|
40
42
|
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
|
|
41
|
-
"@playwright/browser-chromium": "^1.53.
|
|
43
|
+
"@playwright/browser-chromium": "^1.53.1",
|
|
42
44
|
"@rsbuild/plugin-react": "^1.3.2",
|
|
43
45
|
"@rsbuild/plugin-sass": "^1.3.2",
|
|
44
46
|
"@rsbuild/plugin-svgr": "^1.2.0",
|
|
@@ -54,19 +56,20 @@
|
|
|
54
56
|
"commander": "^13.1.0 || ^14.0.0",
|
|
55
57
|
"ejs": "^3.1.10",
|
|
56
58
|
"es-toolkit": "^1.39.3",
|
|
57
|
-
"eslint": "^9.
|
|
58
|
-
"eslint-plugin-mdx": "^3.
|
|
59
|
+
"eslint": "^9.29.0",
|
|
60
|
+
"eslint-plugin-mdx": "^3.5.0",
|
|
61
|
+
"globals": "^16.2.0",
|
|
59
62
|
"html-tag-names": "^2.1.0",
|
|
60
63
|
"mdast-util-mdx": "^3.0.0",
|
|
61
64
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
62
65
|
"mermaid": "^11.6.0",
|
|
63
|
-
"openai": "^5.
|
|
66
|
+
"openai": "^5.5.1",
|
|
64
67
|
"openapi-types": "^12.1.3",
|
|
65
68
|
"p-ratelimit": "^1.0.1",
|
|
66
69
|
"pdf-lib": "^1.17.1",
|
|
67
70
|
"pdf-merger-js": "^5.1.2",
|
|
68
71
|
"picomatch": "^4.0.2",
|
|
69
|
-
"playwright": "^1.53.
|
|
72
|
+
"playwright": "^1.53.1",
|
|
70
73
|
"react-markdown": "^10.1.0",
|
|
71
74
|
"rehype-raw": "^7.0.0",
|
|
72
75
|
"rehype-sanitize": "^6.0.0",
|
|
@@ -81,7 +84,7 @@
|
|
|
81
84
|
"tinyglobby": "^0.2.14",
|
|
82
85
|
"type-fest": "^4.41.0",
|
|
83
86
|
"typescript": "^5.8.3",
|
|
84
|
-
"typescript-eslint": "^8.34.
|
|
87
|
+
"typescript-eslint": "^8.34.1",
|
|
85
88
|
"x-fetch": "^0.2.6",
|
|
86
89
|
"yaml": "^2.8.0",
|
|
87
90
|
"yoctocolors": "^2.1.1"
|