@alauda/doom 0.11.4 → 0.11.5
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 +8 -0
- package/lib/global/VersionsNav/index.js +6 -5
- package/lib/plugins/api/index.js +4 -7
- package/lib/plugins/global/index.js +11 -7
- package/lib/plugins/permission/index.js +3 -3
- package/lib/plugins/shiki/index.d.ts +0 -3
- package/lib/plugins/shiki/index.js +0 -3
- package/lib/runtime/components/ExternalSiteLink.js +6 -4
- package/lib/runtime/components/K8sCrd.js +3 -5
- package/lib/runtime/components/K8sPermissionTable.js +1 -1
- package/lib/runtime/components/OpenAPIPath.js +9 -11
- package/lib/runtime/components/OpenAPIRef.js +5 -8
- package/lib/runtime/components/_ExternalSiteBase.js +3 -2
- package/lib/runtime/components/_RefLink.js +3 -9
- package/lib/runtime/hooks/useSiteOverrides.js +4 -3
- package/lib/runtime/types.d.ts +0 -11
- package/lib/runtime/utils.d.ts +4 -4
- package/lib/runtime/utils.js +10 -6
- package/lib/utils/helpers.d.ts +1 -1
- package/lib/utils/helpers.js +4 -4
- package/package.json +1 -1
package/global.d.ts
CHANGED
|
@@ -13,6 +13,14 @@ declare module 'doom-@api-openapisMap' {
|
|
|
13
13
|
export default openapisMap
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
declare module 'doom-@api-virtual' {
|
|
17
|
+
export default virtual
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare module 'doom-@global-virtual' {
|
|
21
|
+
export default virtual
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
declare module 'doom-@permission-functionResourcesMap' {
|
|
17
25
|
export default functionResourcesMap
|
|
18
26
|
}
|
|
@@ -5,6 +5,7 @@ import { useEffect, useMemo, useState } from 'react';
|
|
|
5
5
|
import { createPortal } from 'react-dom';
|
|
6
6
|
import { parse } from 'yaml';
|
|
7
7
|
import { NavMenuGroup } from './NavMenuGroup.js';
|
|
8
|
+
import virtual from 'doom-@global-virtual';
|
|
8
9
|
const getNavMenu = () => {
|
|
9
10
|
if (typeof document === 'undefined') {
|
|
10
11
|
return null;
|
|
@@ -12,16 +13,16 @@ const getNavMenu = () => {
|
|
|
12
13
|
return document.querySelector('.rspress-nav-menu');
|
|
13
14
|
};
|
|
14
15
|
export const VersionsNav = () => {
|
|
15
|
-
const { siteData
|
|
16
|
+
const { siteData } = usePageData();
|
|
16
17
|
const [versionsBase, version] = useMemo(() => {
|
|
17
|
-
if (!
|
|
18
|
+
if (!virtual.version) {
|
|
18
19
|
return [];
|
|
19
20
|
}
|
|
20
21
|
return [
|
|
21
|
-
removeTrailingSlash(siteData.base).slice(0, -
|
|
22
|
-
|
|
22
|
+
removeTrailingSlash(siteData.base).slice(0, -virtual.version.length - 1),
|
|
23
|
+
virtual.version,
|
|
23
24
|
];
|
|
24
|
-
}, [siteData.base
|
|
25
|
+
}, [siteData.base]);
|
|
25
26
|
const [navMenu, setNavMenu] = useState(getNavMenu);
|
|
26
27
|
const [versions, setVersions] = useState();
|
|
27
28
|
useEffect(() => {
|
package/lib/plugins/api/index.js
CHANGED
|
@@ -4,14 +4,11 @@ import { generateRuntimeModule } from '../../utils/index.js';
|
|
|
4
4
|
export const apiPlugin = ({ localBasePath, crds = [], openapis = [], references, pathPrefix, }) => {
|
|
5
5
|
return {
|
|
6
6
|
name: 'doom-api',
|
|
7
|
-
|
|
8
|
-
pageData.references = references;
|
|
9
|
-
pageData.pathPrefix = pathPrefix;
|
|
10
|
-
},
|
|
11
|
-
async addRuntimeModules(_, isProd) {
|
|
7
|
+
async addRuntimeModules(config, isProd) {
|
|
12
8
|
return {
|
|
13
|
-
|
|
14
|
-
...(await generateRuntimeModule(
|
|
9
|
+
'doom-@api-virtual': `export default ${JSON.stringify({ references, pathPrefix }, null, isProd ? 0 : 2)}`,
|
|
10
|
+
...(await generateRuntimeModule(crds, 'api-crds', config.root, localBasePath, isProd)),
|
|
11
|
+
...(await generateRuntimeModule(openapis, 'api-openapis', config.root, localBasePath, isProd, async (doc) => {
|
|
15
12
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
16
13
|
doc.info ??= { title: 'Unknown', version: '0.0.0' };
|
|
17
14
|
if ('swagger' in doc && doc.swagger === '2.0') {
|
|
@@ -23,13 +23,17 @@ export const globalPlugin = ({ sites, version, } = {}) => {
|
|
|
23
23
|
})
|
|
24
24
|
.map((file) => path.resolve(componentsDir, file)),
|
|
25
25
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
addRuntimeModules(_, isProd) {
|
|
27
|
+
return {
|
|
28
|
+
'doom-@global-virtual': `export default ${JSON.stringify({
|
|
29
|
+
sites: sites?.map((site) => ({
|
|
30
|
+
...site,
|
|
31
|
+
base: addTrailingSlash(site.base || (site.name === 'acp' ? '/container-platform' : '')),
|
|
32
|
+
version: normalizeVersion(site.version),
|
|
33
|
+
})),
|
|
34
|
+
version: version === 'unversioned' ? undefined : version,
|
|
35
|
+
}, null, isProd ? 0 : 2)}`,
|
|
36
|
+
};
|
|
33
37
|
},
|
|
34
38
|
};
|
|
35
39
|
};
|
|
@@ -2,10 +2,10 @@ import { generateRuntimeModule } from '../../utils/index.js';
|
|
|
2
2
|
export const permissionPlugin = ({ localBasePath, functionresources = [], roletemplates = [], }) => {
|
|
3
3
|
return {
|
|
4
4
|
name: 'doom-permission',
|
|
5
|
-
async addRuntimeModules(
|
|
5
|
+
async addRuntimeModules(config, isProd) {
|
|
6
6
|
return {
|
|
7
|
-
...(await generateRuntimeModule(functionresources, 'permission-functionResources', localBasePath, isProd, ({ items }) => items)),
|
|
8
|
-
...(await generateRuntimeModule(roletemplates, 'permission-roleTemplates', localBasePath, isProd, ({ items }) => items)),
|
|
7
|
+
...(await generateRuntimeModule(functionresources, 'permission-functionResources', localBasePath, config.root, isProd, ({ items }) => items)),
|
|
8
|
+
...(await generateRuntimeModule(roletemplates, 'permission-roleTemplates', config.root, localBasePath, isProd, ({ items }) => items)),
|
|
9
9
|
};
|
|
10
10
|
},
|
|
11
11
|
};
|
|
@@ -15,8 +15,5 @@ export interface PluginShikiOptions {
|
|
|
15
15
|
transformers?: ShikiTransformer[];
|
|
16
16
|
}
|
|
17
17
|
export declare const SHIKI_DEFAULT_HIGHLIGHT_LANGUAGES: BuiltinLanguage[];
|
|
18
|
-
/**
|
|
19
|
-
* The plugin is used to add the last updated time to the page.
|
|
20
|
-
*/
|
|
21
18
|
export declare function shikiPlugin({ theme, langs, transformers, }?: PluginShikiOptions): RspressPlugin;
|
|
22
19
|
export * from './transformers/index.js';
|
|
@@ -24,9 +24,6 @@ const cssVariablesTheme = createCssVariablesTheme({
|
|
|
24
24
|
variableDefaults: {},
|
|
25
25
|
fontStyle: true,
|
|
26
26
|
});
|
|
27
|
-
/**
|
|
28
|
-
* The plugin is used to add the last updated time to the page.
|
|
29
|
-
*/
|
|
30
27
|
export function shikiPlugin({ theme = 'css-variables', langs = [], transformers = [], } = {}) {
|
|
31
28
|
return {
|
|
32
29
|
name: 'doom-shiki',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useLang
|
|
2
|
+
import { useLang } from '@rspress/core/runtime';
|
|
3
3
|
import { addTrailingSlash, isExternalUrl, removeLeadingSlash, } from '@rspress/shared';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
import { Directive } from './Directive.js';
|
|
7
|
+
import virtual from 'doom-@global-virtual';
|
|
7
8
|
import classes from '../../../styles/link.module.scss';
|
|
8
9
|
export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
|
|
9
|
-
const
|
|
10
|
-
const site = useMemo(() => page.sites?.find((s) => s.name === name), []);
|
|
10
|
+
const site = useMemo(() => virtual.sites?.find((s) => s.name === name), []);
|
|
11
11
|
const lang = useLang();
|
|
12
12
|
if (!site) {
|
|
13
13
|
return (_jsxs(Directive, { type: "danger", children: ["No site with name `", name, "` found, please ensure it's already defined at `sites.yaml`"] }));
|
|
@@ -15,7 +15,9 @@ export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
|
|
|
15
15
|
if (isExternalUrl(href)) {
|
|
16
16
|
return _jsxs(Directive, { type: "danger", children: ["Invalid href `", href, "` found"] });
|
|
17
17
|
}
|
|
18
|
-
return (_jsx("a", { href: (
|
|
18
|
+
return (_jsx("a", { href: (virtual.version
|
|
19
|
+
? addTrailingSlash(site.base + site.version)
|
|
20
|
+
: site.base) +
|
|
19
21
|
(lang ? `${lang}/` : '') +
|
|
20
22
|
removeLeadingSlash(href), target: "_blank", rel: "noopener noreferrer", className: clsx(classes.link, 'cursor-pointer', className), ...props }));
|
|
21
23
|
};
|
|
@@ -9,7 +9,6 @@ import { Directive } from './Directive.js';
|
|
|
9
9
|
import { Markdown } from './_Markdown.js';
|
|
10
10
|
import crdsMap from 'doom-@api-crdsMap';
|
|
11
11
|
export const K8sCrdSchemaPart = ({ name, parent, schema: property, expandAll, }) => {
|
|
12
|
-
const [X] = useState(getCustomMDXComponent);
|
|
13
12
|
const [open, setOpen] = useState(expandAll);
|
|
14
13
|
const onToggle = useCallback((open) => {
|
|
15
14
|
setOpen(open);
|
|
@@ -38,19 +37,18 @@ export const K8sCrdSchemaPart = ({ name, parent, schema: property, expandAll, })
|
|
|
38
37
|
}
|
|
39
38
|
return [props, required, type, schema];
|
|
40
39
|
}, [name, parent, property]);
|
|
41
|
-
return (_jsx(_Fragment, { children: _jsxs(Directive, { type: "details", title: _jsxs(_Fragment, { children: [name, type && _jsx(
|
|
40
|
+
return (_jsx(_Fragment, { children: _jsxs(Directive, { type: "details", title: _jsxs(_Fragment, { children: [name, type && _jsx("code", { children: type }), required && _jsx(Badge, { children: "required" })] }), open: open, onToggle: onToggle, children: [_jsx(Markdown, { children: schema.description }), props &&
|
|
42
41
|
Object.entries(props).map(([name, subSchema]) => (_jsx(K8sCrdSchemaPart, { name: name, parent: schema, schema: subSchema, expandAll: expandAll }, name)))] }) }));
|
|
43
42
|
};
|
|
44
43
|
const SKIPPED_PROPERTIES = ['apiVersion', 'kind', 'metadata'];
|
|
45
44
|
export const K8sCrdSchema = ({ schema, version, }) => {
|
|
46
|
-
const [X] = useState(getCustomMDXComponent);
|
|
47
45
|
const { description, properties } = schema;
|
|
48
46
|
const t = useTranslation();
|
|
49
47
|
const [expandAll, setExpandAll] = useState(false);
|
|
50
48
|
const toggleExpandAll = useCallback(() => {
|
|
51
49
|
setExpandAll((all) => !all);
|
|
52
50
|
}, []);
|
|
53
|
-
return (_jsxs(_Fragment, { children: [_jsx(Markdown, { children: description }), _jsxs("div", { className: "flex items-center", children: [_jsxs("span", { children: [_jsx(
|
|
51
|
+
return (_jsxs(_Fragment, { children: [_jsx(Markdown, { children: description }), _jsxs("div", { className: "flex items-center", children: [_jsxs("span", { children: [_jsx("code", { children: version }), _jsx(Badge, { children: "version" })] }), properties != null && (_jsx(Button, { className: "ml-auto doom-btn", type: "button", text: _jsxs("span", { onClick: toggleExpandAll, children: [expandAll ? '-' : '+', ' ', t(expandAll ? 'collapse_all' : 'expand_all')] }), size: "medium", theme: "alt" }))] }), properties == null ? (_jsx(Directive, { type: "warning", children: t('crd_no_schema') })) : (_jsx("div", { className: "doom-collapse-group", children: Object.entries(properties).map(([name, subSchema]) => SKIPPED_PROPERTIES.includes(name) || (_jsx(K8sCrdSchemaPart, { name: name, parent: schema, schema: subSchema, expandAll: expandAll }, name))) }))] }));
|
|
54
52
|
};
|
|
55
53
|
export const K8sCrd = ({ name, crdPath }) => {
|
|
56
54
|
const [X] = useState(getCustomMDXComponent);
|
|
@@ -64,6 +62,6 @@ export const K8sCrd = ({ name, crdPath }) => {
|
|
|
64
62
|
console.error(`No CustomResourceDefinition found for ${name}`);
|
|
65
63
|
return null;
|
|
66
64
|
}
|
|
67
|
-
return (_jsxs(_Fragment, { children: [_jsxs(X.p, { children: [_jsx(
|
|
65
|
+
return (_jsxs(_Fragment, { children: [_jsxs(X.p, { children: [_jsx("code", { children: crd.spec.group }), _jsx(Badge, { children: "group" })] }), crd.spec.versions.map((version) => (_jsx(K8sCrdSchema, { schema: version.schema.openAPIV3Schema, version: version.name }, version.name)))] }));
|
|
68
66
|
};
|
|
69
67
|
export default K8sCrd;
|
|
@@ -73,7 +73,7 @@ export const K8sPermissionTable = ({ functions }) => {
|
|
|
73
73
|
const { metadata: { annotations, name }, } = fr;
|
|
74
74
|
return (_jsxs(Fragment, { children: [_jsxs(X.tr, { children: [_jsxs(X.td, { rowSpan: 4, style: TEXT_CENTER_STYLE, children: [isZh
|
|
75
75
|
? annotations[FUNCTION_DISPLAY_NAME_ZH]
|
|
76
|
-
: annotations[FUNCTION_DISPLAY_NAME_EN], _jsx("br", {}), _jsx(
|
|
76
|
+
: annotations[FUNCTION_DISPLAY_NAME_EN], _jsx("br", {}), _jsx("code", { children: name })] }), _jsx(X.td, { children: t('view') }), _jsx(RolesPermission, { functionResource: fr, roleTemplates: roleTemplates, verb: "view" })] }), Verbs.slice(1).map((verb) => (_jsxs(X.tr, { children: [_jsx(X.td, { children: t(verb) }), _jsx(RolesPermission, { functionResource: fr, roleTemplates: roleTemplates, verb: verb })] }, verb)))] }, name));
|
|
77
77
|
}) })] }));
|
|
78
78
|
};
|
|
79
79
|
export default K8sPermissionTable;
|
|
@@ -4,12 +4,13 @@ import { Badge, getCustomMDXComponent } from '@rspress/core/theme';
|
|
|
4
4
|
import BananaSlug from 'github-slugger';
|
|
5
5
|
import { OpenAPIV3 } from 'openapi-types';
|
|
6
6
|
import { Fragment, useMemo, useState } from 'react';
|
|
7
|
-
import {
|
|
7
|
+
import { omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
8
8
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
9
9
|
import { Markdown } from './_Markdown.js';
|
|
10
10
|
import { RefLink } from './_RefLink.js';
|
|
11
11
|
import OpenAPIRef from './OpenAPIRef.js';
|
|
12
12
|
import openapisMap from 'doom-@api-openapisMap';
|
|
13
|
+
import virtual from 'doom-@api-virtual';
|
|
13
14
|
export const OpenAPIParameters = ({ parameters, openapi, }) => {
|
|
14
15
|
const [X] = useState(getCustomMDXComponent);
|
|
15
16
|
return (_jsx(X.ul, { children: parameters.map((param, index) => {
|
|
@@ -20,17 +21,17 @@ export const OpenAPIParameters = ({ parameters, openapi, }) => {
|
|
|
20
21
|
('$ref' in paramObj.schema ? paramObj.schema : paramObj.schema.type);
|
|
21
22
|
let typeNode;
|
|
22
23
|
if (typeof type === 'string') {
|
|
23
|
-
typeNode = _jsx(
|
|
24
|
+
typeNode = _jsx("code", { children: type });
|
|
24
25
|
}
|
|
25
26
|
else if (type) {
|
|
26
27
|
typeNode = _jsx(RefLink, { "$ref": type.$ref });
|
|
27
28
|
}
|
|
28
|
-
return (_jsxs(X.li, { children: [_jsx(
|
|
29
|
+
return (_jsxs(X.li, { children: [_jsx("code", { children: paramObj.name }), "(", _jsxs("em", { children: ["in ", paramObj.in] }), "): ", typeNode, paramObj.required && _jsx(Badge, { children: "required" }), _jsx(Markdown, { children: paramObj.description })] }, index));
|
|
29
30
|
}) }));
|
|
30
31
|
};
|
|
31
32
|
export const OpenAPIResponses = ({ responses, openapi, }) => {
|
|
32
33
|
const [X] = useState(getCustomMDXComponent);
|
|
33
|
-
return (_jsx(X.ul, { children: Object.entries(responses).map(([code, response]
|
|
34
|
+
return (_jsx(X.ul, { children: Object.entries(responses).map(([code, response]) => {
|
|
34
35
|
const responseObj = '$ref' in response
|
|
35
36
|
? resolveRef(openapi, response.$ref)
|
|
36
37
|
: response;
|
|
@@ -39,7 +40,7 @@ export const OpenAPIResponses = ({ responses, openapi, }) => {
|
|
|
39
40
|
if (schema && '$ref' in schema) {
|
|
40
41
|
refNode = (_jsxs(_Fragment, { children: ["(", _jsx(RefLink, { "$ref": schema.$ref }), ")"] }));
|
|
41
42
|
}
|
|
42
|
-
return (_jsxs(X.li, { children: [_jsx(
|
|
43
|
+
return (_jsxs(X.li, { children: [_jsx("code", { children: code }), refNode, ": ", responseObj.description] }, code));
|
|
43
44
|
}) }));
|
|
44
45
|
};
|
|
45
46
|
const getRefsForPath = (openapi, path, knownRefs) => {
|
|
@@ -77,7 +78,7 @@ const getRefsForPath = (openapi, path, knownRefs) => {
|
|
|
77
78
|
export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathPrefix_, }) => {
|
|
78
79
|
const [X] = useState(getCustomMDXComponent);
|
|
79
80
|
const { page } = usePageData();
|
|
80
|
-
const pathPrefix = pathPrefix_ ?? (
|
|
81
|
+
const pathPrefix = pathPrefix_ ?? (virtual.pathPrefix || '');
|
|
81
82
|
const slugger = useMemo(() => new BananaSlug(), []);
|
|
82
83
|
const [pathItem, openapi, openapiPath, refs] = useMemo(() => {
|
|
83
84
|
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
@@ -90,10 +91,7 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
90
91
|
pathItem,
|
|
91
92
|
openapi,
|
|
92
93
|
pathname,
|
|
93
|
-
getRefsForPath(openapi, path, omitRoutePathRefs(
|
|
94
|
-
...page.references,
|
|
95
|
-
...DEFAULT_COMMON_REFS,
|
|
96
|
-
}, page.routePath)),
|
|
94
|
+
getRefsForPath(openapi, path, omitRoutePathRefs(page.routePath)),
|
|
97
95
|
];
|
|
98
96
|
}
|
|
99
97
|
}
|
|
@@ -115,7 +113,7 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
115
113
|
const requestBodySchema = requestBodyRef
|
|
116
114
|
? resolveRef(openapi, requestBodyRef)
|
|
117
115
|
: undefined;
|
|
118
|
-
return (_jsxs(Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, level: 3, children: [_jsx(
|
|
116
|
+
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));
|
|
119
117
|
}), refs?.map((ref) => {
|
|
120
118
|
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, collectRefs: false }, ref));
|
|
121
119
|
})] }));
|
|
@@ -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 { useMemo, useState } from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { modelName, omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
6
6
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
7
7
|
import { Markdown } from './_Markdown.js';
|
|
8
8
|
import { RefLink } from './_RefLink.js';
|
|
@@ -31,16 +31,16 @@ export const OpenAPIProperties = ({ properties, openapi, }) => {
|
|
|
31
31
|
: '$ref' in props && _jsx(RefLink, { "$ref": props.$ref })] }));
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
typeNode = _jsx(
|
|
34
|
+
typeNode = _jsx("code", { children: type });
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
else if (typeof type === 'string') {
|
|
38
|
-
typeNode = _jsx(
|
|
38
|
+
typeNode = _jsx("code", { children: type });
|
|
39
39
|
}
|
|
40
40
|
else if ('$ref' in prop) {
|
|
41
41
|
typeNode = _jsx(RefLink, { "$ref": prop.$ref });
|
|
42
42
|
}
|
|
43
|
-
return (_jsxs(X.li, { children: [_jsx(
|
|
43
|
+
return (_jsxs(X.li, { children: [_jsx("code", { children: name }), ": ", typeNode, _jsx(Markdown, { children: propObj.description })] }, index));
|
|
44
44
|
}) }));
|
|
45
45
|
};
|
|
46
46
|
const getRefsForSchema = (openapi, schema, knownRefs) => {
|
|
@@ -86,10 +86,7 @@ export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, collectRefs = tr
|
|
|
86
86
|
}
|
|
87
87
|
const refs = useMemo(() => {
|
|
88
88
|
if (collectRefs) {
|
|
89
|
-
return getRefsForSchema(openapi, schema, omitRoutePathRefs(
|
|
90
|
-
...page.references,
|
|
91
|
-
...DEFAULT_COMMON_REFS,
|
|
92
|
-
}, page.routePath));
|
|
89
|
+
return getRefsForSchema(openapi, schema, omitRoutePathRefs(page.routePath));
|
|
93
90
|
}
|
|
94
91
|
}, [collectRefs, openapi, page.routePath, schema]);
|
|
95
92
|
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)))] }));
|
|
@@ -4,6 +4,7 @@ import { useMemo } from 'react';
|
|
|
4
4
|
import { handleCJKWhitespaces } from '../utils.js';
|
|
5
5
|
import Directive from './Directive.js';
|
|
6
6
|
import ExternalSiteLink from './ExternalSiteLink.js';
|
|
7
|
+
import virtual from 'doom-@global-virtual';
|
|
7
8
|
const SiteNotes = {
|
|
8
9
|
en({ name, displayName }) {
|
|
9
10
|
return (_jsxs(_Fragment, { children: ["Because ", displayName, " releases on a different cadence from Alauda Container Platform, the ", displayName, " documentation is now available as a separate documentation set at", ' ', _jsx(ExternalSiteLink, { name: name, children: displayName }), "."] }));
|
|
@@ -23,8 +24,8 @@ const ApisOverviewNotes = {
|
|
|
23
24
|
},
|
|
24
25
|
};
|
|
25
26
|
export const ExternalSiteBase = ({ name, template }) => {
|
|
26
|
-
const { siteData
|
|
27
|
-
const site = useMemo(() =>
|
|
27
|
+
const { siteData } = usePageData();
|
|
28
|
+
const site = useMemo(() => virtual.sites?.find((s) => s.name === name), []);
|
|
28
29
|
const lang = useLang() || siteData.lang || 'zh';
|
|
29
30
|
const displayName = useMemo(() => site?.displayName?.[lang] || site?.displayName?.en || name.toUpperCase(), []);
|
|
30
31
|
if (!site) {
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { useMemo, useState } from 'react';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { COMMON_REFS, modelName } from '../utils.js';
|
|
6
5
|
export const RefLink = ({ $ref }) => {
|
|
7
6
|
const [X] = useState(getCustomMDXComponent);
|
|
8
|
-
const { page } = usePageData();
|
|
9
|
-
const references = useMemo(() => ({
|
|
10
|
-
...DEFAULT_COMMON_REFS,
|
|
11
|
-
...page.references,
|
|
12
|
-
}), []);
|
|
13
7
|
if (!$ref) {
|
|
14
8
|
return null;
|
|
15
9
|
}
|
|
16
10
|
const ref = $ref.replace('/components/schemas/', '');
|
|
17
11
|
const refName = modelName(ref);
|
|
18
|
-
return _jsx(X.a, { href:
|
|
12
|
+
return _jsx(X.a, { href: COMMON_REFS[ref.slice(1)] || ref, children: refName });
|
|
19
13
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isProduction, useLang, usePageData } from '@rspress/core/runtime';
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { parse } from 'yaml';
|
|
4
|
+
import virtual from 'doom-@global-virtual';
|
|
4
5
|
const DEFAULT_SITE_BRAND = {
|
|
5
6
|
en: {
|
|
6
7
|
company: 'Alauda',
|
|
@@ -47,15 +48,15 @@ const fetchSiteOverrides = async (base, version, acpSite) => {
|
|
|
47
48
|
}))).catch(() => ({}));
|
|
48
49
|
};
|
|
49
50
|
export const useSiteOverrides = () => {
|
|
50
|
-
const { siteData
|
|
51
|
+
const { siteData } = usePageData();
|
|
51
52
|
const [siteOverridesWithLangs, setSiteOverridesWithLangs] = useState(siteOverrides);
|
|
52
53
|
const lang = useLang() || 'zh';
|
|
53
|
-
const acpSite = useMemo(() =>
|
|
54
|
+
const acpSite = useMemo(() => virtual.sites?.find((s) => s.name === 'acp'), []);
|
|
54
55
|
useEffect(() => {
|
|
55
56
|
if (siteOverrides) {
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
|
-
void fetchSiteOverrides(siteData.base,
|
|
59
|
+
void fetchSiteOverrides(siteData.base, virtual.version, acpSite).then(setSiteOverridesWithLangs);
|
|
59
60
|
}, []);
|
|
60
61
|
return useMemo(() => {
|
|
61
62
|
if (!siteOverridesWithLangs) {
|
package/lib/runtime/types.d.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
import { PageData } from '@rspress/core';
|
|
2
|
-
import type { DoomSite } from '../shared/types.js';
|
|
3
1
|
export interface SiteBrand {
|
|
4
2
|
company: string;
|
|
5
3
|
product: string;
|
|
6
4
|
productShort: string;
|
|
7
5
|
}
|
|
8
|
-
export interface ExtendedPage {
|
|
9
|
-
references?: Record<string, string>;
|
|
10
|
-
pathPrefix?: string;
|
|
11
|
-
sites?: DoomSite[];
|
|
12
|
-
v?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface ExtendedPageData extends PageData {
|
|
15
|
-
page: PageData['page'] & ExtendedPage;
|
|
16
|
-
}
|
package/lib/runtime/utils.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { OpenAPIV3_1 } from 'openapi-types';
|
|
1
|
+
import type { OpenAPIV3_1 } from 'openapi-types';
|
|
2
2
|
export declare const modelName: (ref: string) => string;
|
|
3
3
|
export declare const resolveRef: <T extends object = OpenAPIV3_1.SchemaObject>(openapi: OpenAPIV3_1.Document, ref: string) => T;
|
|
4
|
-
export declare const
|
|
5
|
-
[
|
|
4
|
+
export declare const COMMON_REFS: {
|
|
5
|
+
[x: string]: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const omitRoutePathRefs: (
|
|
7
|
+
export declare const omitRoutePathRefs: (routePath: string) => {
|
|
8
8
|
[k: string]: string;
|
|
9
9
|
};
|
|
10
10
|
export declare const CJK_PATTERN: RegExp;
|
package/lib/runtime/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { last, upperFirst } from 'es-toolkit';
|
|
2
2
|
import { get } from 'es-toolkit/compat';
|
|
3
|
+
import virtual from 'doom-@api-virtual';
|
|
3
4
|
export const modelName = (ref) => upperFirst(last(ref.split('.')));
|
|
4
5
|
export const resolveRef = (openapi, ref) => {
|
|
5
6
|
if (!ref.startsWith('#/')) {
|
|
@@ -7,16 +8,19 @@ export const resolveRef = (openapi, ref) => {
|
|
|
7
8
|
}
|
|
8
9
|
return get(openapi, ref.slice(2).split('/'));
|
|
9
10
|
};
|
|
10
|
-
const
|
|
11
|
+
const DEFAULT_COMMON_REFS = {
|
|
11
12
|
'v1alpha1.ListMeta': 'common-definitions/list-meta/#ListMeta',
|
|
12
13
|
'v1.ObjectMeta': 'common-definitions/object-meta/#ObjectMeta',
|
|
13
14
|
};
|
|
14
15
|
const K8S_DOC_PREFIX = 'https://kubernetes.io/docs/reference/kubernetes-api/';
|
|
15
|
-
export const
|
|
16
|
-
key,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
export const COMMON_REFS = {
|
|
17
|
+
...Object.fromEntries(Object.entries(DEFAULT_COMMON_REFS).map(([key, value]) => [
|
|
18
|
+
key,
|
|
19
|
+
`${K8S_DOC_PREFIX}${value}`,
|
|
20
|
+
])),
|
|
21
|
+
...virtual.references,
|
|
22
|
+
};
|
|
23
|
+
export const omitRoutePathRefs = (routePath) => Object.fromEntries(Object.entries(COMMON_REFS).filter(([, value]) => routePath !== value.split('#')[0]));
|
|
20
24
|
export const CJK_PATTERN = /\p{sc=Han}/u;
|
|
21
25
|
export const handleCJKWhitespaces = (text) => {
|
|
22
26
|
if (!text) {
|
package/lib/utils/helpers.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { StringMapper } from '../shared/types.js';
|
|
|
2
2
|
export declare const baseResolve: (...paths: string[]) => string;
|
|
3
3
|
export declare const pkgResolve: (...paths: string[]) => string;
|
|
4
4
|
export declare const resolveStaticConfig: <T = unknown>(filepath: string) => Promise<T>;
|
|
5
|
-
export declare function generateRuntimeModule<T, R = T>(patterns: string[], kind: string, cwd: string, isProd: boolean, mapper?: (input: T) => R | Promise<R>): Promise<StringMapper>;
|
|
5
|
+
export declare function generateRuntimeModule<T, R = T>(patterns: string[], kind: string, root: string, cwd: string, isProd: boolean, mapper?: (input: T) => R | Promise<R>): Promise<StringMapper>;
|
package/lib/utils/helpers.js
CHANGED
|
@@ -20,11 +20,11 @@ export const resolveStaticConfig = async (filepath) => {
|
|
|
20
20
|
}
|
|
21
21
|
throw new Error(`Unsupported file extension: ${extname}`);
|
|
22
22
|
};
|
|
23
|
-
export async function generateRuntimeModule(patterns, kind, cwd, isProd, mapper) {
|
|
23
|
+
export async function generateRuntimeModule(patterns, kind, root, cwd, isProd, mapper) {
|
|
24
24
|
const runtimeModules = {};
|
|
25
|
-
const files = await glob(patterns, { cwd });
|
|
25
|
+
const files = await glob(patterns, { absolute: true, cwd });
|
|
26
26
|
for (const file of files) {
|
|
27
|
-
const result = await resolveStaticConfig(
|
|
27
|
+
const result = await resolveStaticConfig(file);
|
|
28
28
|
runtimeModules[`doom-@${kind}/${file}.mjs`] =
|
|
29
29
|
`export default ${JSON.stringify((await mapper?.(result)) ?? result, null, isProd ? 0 : 2)}`;
|
|
30
30
|
}
|
|
@@ -32,6 +32,6 @@ export async function generateRuntimeModule(patterns, kind, cwd, isProd, mapper)
|
|
|
32
32
|
files
|
|
33
33
|
.map((file, index) => `import _${index} from 'doom-@${kind}/${file}.mjs'`)
|
|
34
34
|
.join('\n') +
|
|
35
|
-
`\nexport default {${files.map((file, index) => `'${file}':_${index}`).join(',')}}`;
|
|
35
|
+
`\nexport default {${files.map((file, index) => `'${path.relative(root, file)}':_${index}`).join(',')}}`;
|
|
36
36
|
return runtimeModules;
|
|
37
37
|
}
|