@alauda/doom 0.3.3 → 0.4.1

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.
Files changed (67) hide show
  1. package/lib/cli/constants.d.ts +1 -0
  2. package/lib/cli/constants.js +1 -0
  3. package/lib/cli/index.js +5 -5
  4. package/lib/cli/load-config.d.ts +1 -1
  5. package/lib/cli/load-config.js +30 -23
  6. package/lib/{cli/config.d.ts → config.d.ts} +1 -1
  7. package/lib/global/VersionsNav/Down.d.ts +1 -0
  8. package/lib/global/VersionsNav/Down.js +2 -0
  9. package/lib/global/VersionsNav/NavMenuGroup.d.ts +12 -0
  10. package/lib/global/VersionsNav/NavMenuGroup.js +53 -0
  11. package/lib/global/VersionsNav/NavMenuSingleItem.d.ts +10 -0
  12. package/lib/global/VersionsNav/NavMenuSingleItem.js +9 -0
  13. package/lib/global/VersionsNav/SvgWrapper.d.ts +7 -0
  14. package/lib/global/VersionsNav/SvgWrapper.js +14 -0
  15. package/lib/global/VersionsNav/index.d.ts +2 -0
  16. package/lib/global/VersionsNav/index.js +55 -0
  17. package/lib/plugins/api/index.js +3 -3
  18. package/lib/plugins/global/index.js +8 -0
  19. package/lib/runtime/components/Badge.d.ts +1 -0
  20. package/lib/runtime/components/Badge.js +1 -0
  21. package/lib/runtime/components/Card.d.ts +1 -0
  22. package/lib/runtime/components/Card.js +1 -0
  23. package/lib/runtime/components/ExternalSite.d.ts +9 -0
  24. package/lib/runtime/components/ExternalSite.js +28 -0
  25. package/lib/runtime/components/K8sCrd.js +1 -1
  26. package/lib/runtime/components/LinkCard.d.ts +1 -0
  27. package/lib/runtime/components/LinkCard.js +1 -0
  28. package/lib/runtime/components/OpenAPIRef.js +1 -1
  29. package/lib/runtime/components/PackageManagerTabs.d.ts +1 -0
  30. package/lib/runtime/components/PackageManagerTabs.js +1 -0
  31. package/lib/runtime/components/Steps.d.ts +1 -0
  32. package/lib/runtime/components/Steps.js +1 -0
  33. package/lib/runtime/components/Tab.d.ts +1 -0
  34. package/lib/runtime/components/Tab.js +1 -0
  35. package/lib/runtime/components/Tabs.d.ts +1 -0
  36. package/lib/runtime/components/Tabs.js +1 -0
  37. package/lib/runtime/components/Toc.d.ts +1 -0
  38. package/lib/runtime/components/Toc.js +1 -0
  39. package/lib/runtime/components/_Directive.d.ts +10 -0
  40. package/lib/runtime/components/_Directive.js +16 -0
  41. package/lib/runtime/components/index.d.ts +10 -1
  42. package/lib/runtime/components/index.js +10 -1
  43. package/lib/runtime/types.d.ts +2 -0
  44. package/lib/runtime/utils.d.ts +2 -0
  45. package/lib/runtime/utils.js +5 -0
  46. package/lib/utils/types.d.ts +8 -0
  47. package/package.json +3 -1
  48. package/styles/versions-nav.module.scss +11 -0
  49. package/lib/cli/shiki/index.d.ts +0 -1
  50. package/lib/cli/shiki/index.js +0 -1
  51. package/lib/cli/shiki/transformers/callouts.d.ts +0 -7
  52. package/lib/cli/shiki/transformers/callouts.js +0 -16
  53. package/lib/cli/shiki/transformers/index.d.ts +0 -1
  54. package/lib/cli/shiki/transformers/index.js +0 -1
  55. package/lib/cli/shiki/types.d.ts +0 -14
  56. package/lib/cli/shiki/types.js +0 -1
  57. package/lib/cli/shiki/utils.d.ts +0 -4
  58. package/lib/cli/shiki/utils.js +0 -47
  59. package/lib/plugins/swagger/index.d.ts +0 -2
  60. package/lib/plugins/swagger/index.js +0 -38
  61. package/lib/plugins/swagger/types.d.ts +0 -28
  62. package/lib/plugins/swagger/types.js +0 -1
  63. package/lib/runtime/components/SwaggerModel.d.ts +0 -5
  64. package/lib/runtime/components/SwaggerModel.js +0 -5
  65. package/lib/runtime/components/SwaggerPath.d.ts +0 -5
  66. package/lib/runtime/components/SwaggerPath.js +0 -32
  67. /package/lib/{cli/config.js → config.js} +0 -0
@@ -6,4 +6,5 @@ export declare const JS_EXTENSIONS: readonly [".js", ".ts", ".mjs", ".mts", ".cj
6
6
  export declare const DEFAULT_EXTENSIONS: readonly [".yaml", ".yml", ".js", ".ts", ".mjs", ".mts", ".cjs", ".cts"];
7
7
  export declare const DEFAULT_CONFIGS: ("doom.config.yaml" | "doom.config.yml" | "doom.config.js" | "doom.config.ts" | "doom.config.mjs" | "doom.config.mts" | "doom.config.cjs" | "doom.config.cts")[];
8
8
  export declare const I18N_FILE = "i18n.json";
9
+ export declare const SITES_FILE = "sites.yaml";
9
10
  export declare const CWD: string;
@@ -19,4 +19,5 @@ export const DEFAULT_EXTENSIONS = [
19
19
  ];
20
20
  export const DEFAULT_CONFIGS = DEFAULT_EXTENSIONS.map((ext) => `${DEFAULT_CONFIG_NAME}${ext}`);
21
21
  export const I18N_FILE = 'i18n.json';
22
+ export const SITES_FILE = 'sites.yaml';
22
23
  export const CWD = process.cwd();
package/lib/cli/index.js CHANGED
@@ -2,18 +2,17 @@
2
2
  /**
3
3
  * Adopted from @see https://github.com/web-infra-dev/rspress/blob/main/packages/cli/src/index.ts
4
4
  */
5
+ import module from 'node:module';
5
6
  import path from 'node:path';
6
7
  import { logger } from '@rsbuild/core';
7
8
  import { build, dev, serve } from '@rspress/core';
8
9
  import { watch } from 'chokidar';
9
- // import type { EventName } from 'chokidar/handler.js'
10
10
  import { program } from 'commander';
11
11
  import { green } from 'yoctocolors';
12
- import module from 'node:module';
13
- import { CWD, DEFAULT_CONFIGS, I18N_FILE } from './constants.js';
12
+ import { CWD, DEFAULT_CONFIGS, I18N_FILE, SITES_FILE } from './constants.js';
14
13
  import { loadConfig } from './load-config.js';
15
14
  const META_FILE = '_meta.json';
16
- const CONFIG_FILES = [...DEFAULT_CONFIGS, I18N_FILE];
15
+ const CONFIG_FILES = [...DEFAULT_CONFIGS, I18N_FILE, SITES_FILE];
17
16
  const setNodeEnv = (env) => {
18
17
  process.env.NODE_ENV = env;
19
18
  };
@@ -51,7 +50,7 @@ program
51
50
  devServer = undefined;
52
51
  }
53
52
  cliWatcher = watch(filepath
54
- ? [filepath, docDirectory, config.i18nSourcePath]
53
+ ? [filepath, config.i18nSourcePath, docDirectory, SITES_FILE]
55
54
  : [...CONFIG_FILES, docDirectory], {
56
55
  ignoreInitial: true,
57
56
  ignored: ['**/node_modules/**', '**/.git/**', '**/.DS_Store/**'],
@@ -59,6 +58,7 @@ program
59
58
  });
60
59
  let isRestarting = false;
61
60
  cliWatcher.on('all', async (eventName, filepath) => {
61
+ console.log(eventName, filepath);
62
62
  if (eventName === 'add' ||
63
63
  eventName === 'unlink' ||
64
64
  (eventName === 'change' &&
@@ -1,4 +1,4 @@
1
- import { DoomConfig } from '../utils/types.js';
1
+ import { type DoomConfig } from '../utils/index.js';
2
2
  export declare function loadConfig(root?: string, configFile?: string): Promise<{
3
3
  config: DoomConfig;
4
4
  filepath?: string;
@@ -7,14 +7,22 @@ import { logger } from '@rspress/shared/logger';
7
7
  import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
8
8
  import getPort from 'get-port';
9
9
  import rehypeRaw from 'rehype-raw';
10
- import { parse } from 'yaml';
11
10
  import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, globalPlugin, shikiPlugin, } from '../plugins/index.js';
12
- import { pkgResolve } from '../utils/helpers.js';
13
- import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, YAML_EXTENSIONS, } from './constants.js';
11
+ import { pkgResolve, resolveStaticConfig, } from '../utils/index.js';
12
+ import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
14
13
  const DEFAULT_LOGO = '/logo.svg';
14
+ const zhLocaleConfig = {
15
+ searchPlaceholderText: '搜索文档',
16
+ searchNoResultsText: '未搜索到相关结果',
17
+ searchSuggestedQueryText: '可更换不同的关键字后重试',
18
+ outlineTitle: '本页概览',
19
+ prevPageText: '上一页',
20
+ nextPageText: '下一页',
21
+ };
15
22
  const getCommonConfig = async (config) => {
23
+ const fallbackToZh = 'lang' in config && config.lang == null;
16
24
  return {
17
- lang: 'en',
25
+ lang: fallbackToZh ? 'zh' : config.lang,
18
26
  route: {
19
27
  exclude: [
20
28
  'dist/**/*',
@@ -36,24 +44,14 @@ const getCommonConfig = async (config) => {
36
44
  },
37
45
  themeConfig: {
38
46
  enableScrollToTop: true,
39
- locales: 'lang' in config && config.lang == null
40
- ? undefined
41
- : [
42
- {
43
- lang: 'zh',
44
- label: '简体中文',
45
- searchPlaceholderText: '搜索文档',
46
- searchNoResultsText: '未搜索到相关结果',
47
- searchSuggestedQueryText: '可更换不同的关键字后重试',
48
- outlineTitle: '本页概览',
49
- prevPageText: '上一页',
50
- nextPageText: '下一页',
51
- },
52
- {
53
- lang: 'en',
54
- label: 'English',
55
- },
56
- ],
47
+ ...(fallbackToZh
48
+ ? zhLocaleConfig
49
+ : {
50
+ locales: [
51
+ { lang: 'zh', label: '简体中文', ...zhLocaleConfig },
52
+ { lang: 'en', label: 'English' },
53
+ ],
54
+ }),
57
55
  },
58
56
  plugins: [
59
57
  pluginPreview({
@@ -126,7 +124,7 @@ export async function loadConfig(root, configFile) {
126
124
  else {
127
125
  try {
128
126
  if (YAML_EXTENSIONS.includes(path.extname(configFilePath))) {
129
- config = parse(fs.readFileSync(configFilePath, 'utf-8'));
127
+ config = await resolveStaticConfig(configFilePath);
130
128
  }
131
129
  else {
132
130
  const { content } = await loadConfig({
@@ -141,6 +139,15 @@ export async function loadConfig(root, configFile) {
141
139
  }
142
140
  }
143
141
  config ??= {};
142
+ if (config.sites) {
143
+ logger.error('Use separate `sites.yaml` config in repository root instead');
144
+ }
145
+ else {
146
+ const sitesConfigFilePath = path.resolve(SITES_FILE);
147
+ if (fs.existsSync(sitesConfigFilePath)) {
148
+ config.sites = await resolveStaticConfig(sitesConfigFilePath);
149
+ }
150
+ }
144
151
  const mergedConfig = mergeRsbuildConfig(await getCommonConfig(config), config);
145
152
  const base = addLeadingSlash(mergedConfig.base || '/');
146
153
  mergedConfig.base = base;
@@ -1,2 +1,2 @@
1
- import { DoomConfig } from '../utils/index.js';
1
+ import { DoomConfig } from './utils/index.js';
2
2
  export declare const defineConfig: (config: DoomConfig) => DoomConfig;
@@ -0,0 +1 @@
1
+ export declare const SvgDown: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export const SvgDown = () => (_jsx("svg", { width: "1em", height: "1em", viewBox: "0 0 32 32", children: _jsx("path", { fill: "currentColor", d: "M16 22L6 12l1.4-1.4l8.6 8.6l8.6-8.6L26 12z" }) }));
@@ -0,0 +1,12 @@
1
+ import { type NavItem } from '@rspress/shared';
2
+ export interface NavMenuGroupItem {
3
+ text?: string | React.ReactElement;
4
+ link?: string;
5
+ items: NavItem[];
6
+ tag?: string;
7
+ activeValue?: string;
8
+ pathname?: string;
9
+ base?: string;
10
+ langs?: string[];
11
+ }
12
+ export declare function NavMenuGroup(item: NavMenuGroupItem): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Tag } from '@rspress/core/theme';
3
+ import { withoutBase, } from '@rspress/shared';
4
+ import { useState } from 'react';
5
+ import { SvgDown } from './Down.js';
6
+ import { NavMenuSingleItem } from './NavMenuSingleItem.js';
7
+ import { SvgWrapper } from './SvgWrapper.js';
8
+ function ActiveGroupItem({ item }) {
9
+ return (_jsxs("div", { className: "rounded-2xl my-1 flex", style: {
10
+ padding: '0.4rem 1.5rem 0.4rem 0.75rem',
11
+ }, children: [item.tag && _jsx(Tag, { tag: item.tag }), _jsx("span", { className: "text-brand", children: item.text })] }, item.link));
12
+ }
13
+ function NormalGroupItem({ item }) {
14
+ return (_jsx("div", { className: "font-medium my-1", children: _jsx("a", { href: item.link, children: _jsx("div", { className: "rounded-2xl hover:bg-mute", style: {
15
+ padding: '0.4rem 1.5rem 0.4rem 0.75rem',
16
+ }, children: _jsxs("div", { className: "flex", children: [item.tag && _jsx(Tag, { tag: item.tag }), _jsx("span", { children: item.text })] }) }) }) }, item.link));
17
+ }
18
+ export function NavMenuGroup(item) {
19
+ const { activeValue, items: groupItems, base = '', link = '', pathname = '', } = item;
20
+ const [isOpen, setIsOpen] = useState(false);
21
+ const renderLinkItem = (item) => {
22
+ const isLinkActive = new RegExp(item.activeMatch || item.link).test(withoutBase(pathname, base));
23
+ if (activeValue === item.text || (!activeValue && isLinkActive)) {
24
+ return _jsx(ActiveGroupItem, { item: item }, item.link);
25
+ }
26
+ return _jsx(NormalGroupItem, { item: item }, item.link);
27
+ };
28
+ const renderGroup = (item) => {
29
+ return (_jsxs("div", { children: ['link' in item ? (renderLinkItem(item)) : (_jsx("p", { className: "font-bold text-gray-400 my-1 not:first:border", children: item.text })), item.items.map(renderLinkItem)] }));
30
+ };
31
+ return (_jsxs("div", { className: "relative flex-center h-14", onMouseLeave: () => {
32
+ setIsOpen(false);
33
+ }, children: [_jsx("button", { onMouseEnter: () => {
34
+ setIsOpen(true);
35
+ }, className: "rspress-nav-menu-group-button flex-center items-center font-medium text-sm text-text-1 hover:text-text-2 transition-colors duration-200", children: link ? (
36
+ // @ts-expect-error item.text may be ReactElement
37
+ _jsx(NavMenuSingleItem, { ...item, rightIcon: _jsx(SvgWrapper, { icon: SvgDown }) })) : (_jsxs(_Fragment, { children: [_jsxs("span", { className: "text-sm font-medium flex", style: {
38
+ marginRight: '2px',
39
+ }, children: [_jsx(Tag, { tag: item.tag }), item.text] }), _jsx(SvgWrapper, { icon: SvgDown })] })) }), _jsx("div", { className: "rspress-nav-menu-group-content absolute mx-0.8 transition-opacity duration-300", style: {
40
+ opacity: isOpen ? 1 : 0,
41
+ visibility: isOpen ? 'visible' : 'hidden',
42
+ right: 0,
43
+ top: '52px',
44
+ }, children: _jsx("div", { className: "p-3 pr-2 w-full h-full max-h-100vh whitespace-nowrap", style: {
45
+ boxShadow: 'var(--rp-shadow-3)',
46
+ zIndex: 100,
47
+ border: '1px solid var(--rp-c-divider-light)',
48
+ borderRadius: 'var(--rp-radius-large)',
49
+ background: 'var(--rp-c-bg)',
50
+ }, children: groupItems.map((item) => {
51
+ return (_jsx("div", { children: 'items' in item ? renderGroup(item) : renderLinkItem(item) }, item.text));
52
+ }) }) })] }));
53
+ }
@@ -0,0 +1,10 @@
1
+ import { type NavItemWithLink, type NavItemWithLinkAndChildren } from '@rspress/shared';
2
+ interface Props {
3
+ pathname: string;
4
+ langs?: string[];
5
+ base: string;
6
+ rightIcon?: React.ReactNode;
7
+ compact?: boolean;
8
+ }
9
+ export declare function NavMenuSingleItem(item: (NavItemWithLink | NavItemWithLinkAndChildren) & Props): import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Tag } from '@rspress/core/theme';
3
+ import { withoutBase, } from '@rspress/shared';
4
+ import styles from '../../../styles/versions-nav.module.scss';
5
+ export function NavMenuSingleItem(item) {
6
+ const { pathname, base } = item;
7
+ const isActive = new RegExp(item.activeMatch || item.link).test(withoutBase(pathname, base));
8
+ return (_jsx("a", { href: item.link, children: _jsxs("div", { className: `rspress-nav-menu-item ${styles.singleItem} ${isActive ? styles.activeItem : ''} text-sm font-medium ${item.compact ? 'mx-0.5' : 'mx-1.5'} px-3 py-2 flex items-center`, children: [_jsx(Tag, { tag: item.tag }), item.text, item.rightIcon] }, item.text) }));
9
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A wrapper for custom SVG icon.
3
+ * When the user uses a custom SVG, the imported icon can be a string or a React component.
4
+ */
5
+ export declare function SvgWrapper({ icon: Icon, ...rest }: {
6
+ icon: string | React.FC<React.SVGProps<SVGSVGElement>>;
7
+ } & React.SVGAttributes<SVGSVGElement | HTMLImageElement>): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * A wrapper for custom SVG icon.
4
+ * When the user uses a custom SVG, the imported icon can be a string or a React component.
5
+ */
6
+ export function SvgWrapper({ icon: Icon, ...rest }) {
7
+ if (!Icon) {
8
+ return null;
9
+ }
10
+ if (typeof Icon === 'string') {
11
+ return _jsx("img", { src: Icon, ...rest });
12
+ }
13
+ return _jsx(Icon, { ...rest });
14
+ }
@@ -0,0 +1,2 @@
1
+ export declare const VersionsNav: () => import("react").ReactPortal | null;
2
+ export default VersionsNav;
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { usePageData } from '@rspress/core/runtime';
3
+ import { noop } from 'es-toolkit';
4
+ import { useEffect, useMemo, useState } from 'react';
5
+ import { createPortal } from 'react-dom';
6
+ import { parse } from 'yaml';
7
+ import { NavMenuGroup } from './NavMenuGroup.js';
8
+ export const VersionsNav = () => {
9
+ const { siteData } = usePageData();
10
+ const [versionsBase, version] = useMemo(() => {
11
+ const parts = siteData.base.split('/');
12
+ const last = parts.at(-1);
13
+ return last === 'master' || /^v\d+\.\d$/.test(last)
14
+ ? [parts.slice(0, -1).join('/'), last]
15
+ : [];
16
+ }, [siteData.base]);
17
+ const [navMenu, setNavMenu] = useState();
18
+ const [versions, setVersions] = useState();
19
+ useEffect(() => {
20
+ const fetchVersions = async () => {
21
+ if (versionsBase == null) {
22
+ return;
23
+ }
24
+ const res = await fetch(`${versionsBase}/versions.yaml`);
25
+ const text = await res.text();
26
+ setNavMenu(document.querySelector('.rspress-nav-menu'));
27
+ setVersions(parse(text));
28
+ };
29
+ fetchVersions().catch(noop);
30
+ }, []);
31
+ // hack way to detect nav menu recreation on theme change
32
+ useEffect(() => {
33
+ if (!navMenu) {
34
+ return;
35
+ }
36
+ const observer = new MutationObserver((mutations) => {
37
+ if (mutations.some((m) => m.removedNodes.length)) {
38
+ setNavMenu(document.querySelector('.rspress-nav-menu'));
39
+ }
40
+ });
41
+ observer.observe(navMenu, { childList: true });
42
+ return () => {
43
+ observer.disconnect();
44
+ };
45
+ }, [navMenu]);
46
+ if (!versions?.length) {
47
+ return null;
48
+ }
49
+ return createPortal(_jsx(NavMenuGroup, { text: version, base: versionsBase, items: versions.map((v) => ({
50
+ text: v,
51
+ link: `${versionsBase}/${v}/`,
52
+ activeMatch: v,
53
+ })), pathname: siteData.base }), document.querySelector('.rspress-nav-menu'));
54
+ };
55
+ export default VersionsNav;
@@ -3,10 +3,10 @@ import { openapiSchemaToJsonSchema } from '@openapi-contrib/openapi-schema-to-js
3
3
  import { convertObj } from 'swagger2openapi';
4
4
  import { glob } from 'tinyglobby';
5
5
  import { resolveStaticConfig } from '../../utils/index.js';
6
- const crdsMap = {};
7
- const openapisMap = {};
8
- const shared = {};
9
6
  export const apiPlugin = () => {
7
+ const crdsMap = {};
8
+ const openapisMap = {};
9
+ const shared = {};
10
10
  return {
11
11
  name: 'doom-api',
12
12
  async beforeBuild(config_) {
@@ -3,9 +3,11 @@ import path from 'node:path';
3
3
  import { baseResolve, pkgResolve } from '../../utils/index.js';
4
4
  const componentsDir = baseResolve('runtime/components');
5
5
  export const globalPlugin = () => {
6
+ let config;
6
7
  return {
7
8
  name: 'doom-global',
8
9
  globalStyles: pkgResolve('styles/global.scss'),
10
+ globalUIComponents: [baseResolve('global/VersionsNav/index.tsx')],
9
11
  markdown: {
10
12
  globalComponents: fs
11
13
  .readdirSync(componentsDir)
@@ -17,5 +19,11 @@ export const globalPlugin = () => {
17
19
  })
18
20
  .map((file) => path.resolve(componentsDir, file)),
19
21
  },
22
+ beforeBuild(config_) {
23
+ config = config_;
24
+ },
25
+ extendPageData(pageData) {
26
+ pageData.sites = config.sites;
27
+ },
20
28
  };
21
29
  };
@@ -0,0 +1 @@
1
+ export { Badge, Badge as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Badge, Badge as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Card, Card as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Card, Card as default } from '@rspress/core/theme';
@@ -0,0 +1,9 @@
1
+ export interface ExternalSiteProps {
2
+ name: string;
3
+ }
4
+ export interface ExternalSiteNoteProps {
5
+ name: string;
6
+ href: string;
7
+ }
8
+ export declare const ExternalSite: ({ name }: ExternalSiteProps) => import("react/jsx-runtime").JSX.Element;
9
+ export default ExternalSite;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLang, usePageData } from '@rspress/core/runtime';
3
+ import { addTrailingSlash } from '@rspress/shared';
4
+ import { useMemo } from 'react';
5
+ import { handleCJKWhitespaces } from '../utils.js';
6
+ import { Directive } from './_Directive.js';
7
+ const Notes = {
8
+ en({ name, href }) {
9
+ return (_jsxs(_Fragment, { children: ["Because ", name, " releases on a different cadence from Alauda Container Platform, the ", name, " documentation is now available as a separate documentation set at", ' ', _jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", children: name }), "."] }));
10
+ },
11
+ zh({ name, href }) {
12
+ const name_ = handleCJKWhitespaces(name);
13
+ return (_jsxs(_Fragment, { children: ["\u56E0\u4E3A", name_, "\u7684\u53D1\u7248\u5468\u671F\u4E0E\u7075\u96C0\u4E91\u5BB9\u5668\u5E73\u53F0\u4E0D\u540C\uFF0C\u6240\u4EE5", name_, "\u7684\u6587\u6863\u73B0\u5728\u4F5C\u4E3A\u72EC\u7ACB\u7684\u6587\u6863\u7AD9\u70B9\u6258\u7BA1\u5728", name_.startsWith(' ') ? ' ' : '', _jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", children: name }), "\u3002"] }));
14
+ },
15
+ };
16
+ export const ExternalSite = ({ name }) => {
17
+ const { siteData, page } = usePageData();
18
+ const site = useMemo(() => page.sites?.find((s) => s.name === name), []);
19
+ const fallbackLang = siteData.lang || 'zh';
20
+ const lang = useLang() || fallbackLang;
21
+ const displayName = useMemo(() => site?.displayName?.[lang] || site?.displayName?.[fallbackLang] || name, []);
22
+ if (!site) {
23
+ return (_jsxs(Directive, { type: "danger", children: ["No site with name `", name, "` found, please ensure it's already defined at `sites.yaml`"] }));
24
+ }
25
+ const Note = Notes[lang] || Notes[fallbackLang] || Notes.en;
26
+ return (_jsx(Directive, { title: "Note", children: _jsx(Note, { name: displayName, href: addTrailingSlash(site.base) }) }));
27
+ };
28
+ export default ExternalSite;
@@ -6,8 +6,8 @@ import { usePageData } from '@rspress/core/runtime';
6
6
  import { Badge, Button, getCustomMDXComponent } from '@rspress/core/theme';
7
7
  import { useCallback, useEffect, useMemo, useState } from 'react';
8
8
  import { useTranslation } from '../hooks/index.js';
9
+ import { Directive } from './_Directive.js';
9
10
  import { Markdown } from './_Markdown.js';
10
- import Directive from './Directive.js';
11
11
  const X = getCustomMDXComponent();
12
12
  export const K8sCrdSchemaPart = ({ name, parent, schema: property, openAll, }) => {
13
13
  const [open, setOpen] = useState(openAll);
@@ -0,0 +1 @@
1
+ export { LinkCard, LinkCard as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { LinkCard, LinkCard as default } from '@rspress/core/theme';
@@ -1,6 +1,6 @@
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
- import { getCustomMDXComponent } from '@rspress/theme-default';
3
+ import { getCustomMDXComponent } from '@rspress/core/theme';
4
4
  import { useMemo } from 'react';
5
5
  import { DEFAULT_COMMON_REFS, modelName, omitRoutePathRefs, resolveRef, } from '../utils.js';
6
6
  import { HeadingTitle } from './_HeadingTitle.js';
@@ -0,0 +1 @@
1
+ export { PackageManagerTabs, PackageManagerTabs as default, } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { PackageManagerTabs, PackageManagerTabs as default, } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Steps, Steps as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Steps, Steps as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Tab, Tab as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Tab, Tab as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Tabs, Tabs as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Tabs, Tabs as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Toc, Toc as default } from '@rspress/core/theme';
@@ -0,0 +1 @@
1
+ export { Toc, Toc as default } from '@rspress/core/theme';
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from 'react';
2
+ export interface DirectiveProps {
3
+ type?: 'danger' | 'details' | 'info' | 'note' | 'tip' | 'warning';
4
+ children: ReactNode;
5
+ className?: string;
6
+ title?: ReactNode;
7
+ open?: boolean;
8
+ onToggle?: (open: boolean) => void;
9
+ }
10
+ export declare const Directive: ({ className, type, title, children, open, onToggle, }: DirectiveProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ import { upperCase } from 'es-toolkit';
4
+ import { useCallback } from 'react';
5
+ export const Directive = ({ className, type = 'info', title, children, open, onToggle, }) => {
6
+ const rootClassName = clsx('rspress-directive', type, className);
7
+ const titleNode = title || upperCase(type);
8
+ const contentNode = (_jsx("div", { className: "rspress-directive-content", children: children }));
9
+ const handleToggle = useCallback((ev) => {
10
+ onToggle?.(ev.currentTarget.open);
11
+ }, [onToggle]);
12
+ if (type === 'details') {
13
+ return (_jsxs("details", { className: rootClassName, open: open, onToggle: handleToggle, children: [_jsx("summary", { className: "rspress-directive-title", children: titleNode }), contentNode] }));
14
+ }
15
+ return (_jsxs("div", { className: rootClassName, children: [_jsx("div", { className: "rspress-directive-title", children: titleNode }), contentNode] }));
16
+ };
@@ -1,6 +1,15 @@
1
+ export * from './Badge.js';
1
2
  export * from './Callouts.js';
3
+ export * from './Card.js';
4
+ export * from './ExternalSite.js';
2
5
  export * from './K8sCrd.js';
6
+ export * from './LinkCard.js';
3
7
  export * from './Overview.js';
4
- export * from './QuickNav.js';
5
8
  export * from './OpenAPIRef.js';
6
9
  export * from './OpenAPIPath.js';
10
+ export * from './PackageManagerTabs.js';
11
+ export * from './QuickNav.js';
12
+ export * from './Steps.js';
13
+ export * from './Tab.js';
14
+ export * from './Tabs.js';
15
+ export * from './Toc.js';
@@ -1,6 +1,15 @@
1
+ export * from './Badge.js';
1
2
  export * from './Callouts.js';
3
+ export * from './Card.js';
4
+ export * from './ExternalSite.js';
2
5
  export * from './K8sCrd.js';
6
+ export * from './LinkCard.js';
3
7
  export * from './Overview.js';
4
- export * from './QuickNav.js';
5
8
  export * from './OpenAPIRef.js';
6
9
  export * from './OpenAPIPath.js';
10
+ export * from './PackageManagerTabs.js';
11
+ export * from './QuickNav.js';
12
+ export * from './Steps.js';
13
+ export * from './Tab.js';
14
+ export * from './Tabs.js';
15
+ export * from './Toc.js';
@@ -1,11 +1,13 @@
1
1
  import { PageData } from '@rspress/core';
2
2
  import { OpenAPIV3_1 } from 'openapi-types';
3
3
  import type { CustomResourceDefinition } from '../plugins/api/types.js';
4
+ import { DoomSite } from '../utils/types.js';
4
5
  export interface ExtendedPage {
5
6
  crdsMap?: Record<string, CustomResourceDefinition>;
6
7
  openapisMap?: Record<string, OpenAPIV3_1.Document>;
7
8
  references?: Record<string, string>;
8
9
  pathPrefix?: string;
10
+ sites?: DoomSite[];
9
11
  }
10
12
  export interface ExtendedPageData extends PageData {
11
13
  page: PageData['page'] & ExtendedPage;
@@ -7,3 +7,5 @@ export declare const DEFAULT_COMMON_REFS: {
7
7
  export declare const omitRoutePathRefs: (refs: Record<string, string>, routePath: string) => {
8
8
  [k: string]: string;
9
9
  };
10
+ export declare const CJK_PATTERN: RegExp;
11
+ export declare const handleCJKWhitespaces: (text: string) => string;
@@ -17,3 +17,8 @@ export const DEFAULT_COMMON_REFS = Object.fromEntries(Object.entries(DEFAULT_COM
17
17
  `${K8S_DOC_PREFIX}${value}`,
18
18
  ]));
19
19
  export const omitRoutePathRefs = (refs, routePath) => Object.fromEntries(Object.entries(refs).filter(([, value]) => routePath !== value.split('#')[0]));
20
+ export const CJK_PATTERN = /\p{sc=Han}/u;
21
+ export const handleCJKWhitespaces = (text) => {
22
+ text = text.at(0)?.match(CJK_PATTERN) ? text : ` ${text}`;
23
+ return text.at(-1)?.match(CJK_PATTERN) ? text : `${text} `;
24
+ };
@@ -1,4 +1,11 @@
1
1
  import { UserConfig } from '@rspress/core';
2
+ export interface DoomSite {
3
+ name: string;
4
+ displayName?: Record<string, string>;
5
+ repo: string;
6
+ base: string;
7
+ defaultVersion?: string;
8
+ }
2
9
  export interface DoomConfig extends UserConfig {
3
10
  api?: {
4
11
  crds?: string[];
@@ -6,4 +13,5 @@ export interface DoomConfig extends UserConfig {
6
13
  references?: Record<string, string>;
7
14
  pathPrefix?: string;
8
15
  };
16
+ sites?: DoomSite[];
9
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.3.3",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -14,6 +14,7 @@
14
14
  "bin": "lib/cli/index.js",
15
15
  "exports": {
16
16
  "./package.json": "./package.json",
17
+ "./config": "./lib/config.js",
17
18
  "./runtime": "./lib/runtime/index.js"
18
19
  },
19
20
  "files": [
@@ -63,6 +64,7 @@
63
64
  "@types/eslint__js": "^8.42.3",
64
65
  "@types/fs-extra": "^11.0.4",
65
66
  "@types/node": "^18.19.68",
67
+ "@types/react-dom": "^18.3.5",
66
68
  "@types/swagger2openapi": "^7.0.4",
67
69
  "eslint": "^9.17.0",
68
70
  "lint-staged": "^15.2.11",
@@ -0,0 +1,11 @@
1
+ .singleItem {
2
+ word-break: keep-all;
3
+ }
4
+
5
+ .activeItem,
6
+ .singleItem:hover {
7
+ background-color: var(--rp-c-bg-mute);
8
+ cursor: pointer;
9
+ color: var(--rp-c-link);
10
+ border-radius: var(--rp-radius);
11
+ }
@@ -1 +0,0 @@
1
- export * from './transformers/index.js';
@@ -1 +0,0 @@
1
- export * from './transformers/index.js';
@@ -1,7 +0,0 @@
1
- import { PluginShikiOptions } from '@rspress/plugin-shiki';
2
- import { IRangeTransformerOptions } from '../types.js';
3
- export interface ITransformerCalloutsOptions extends IRangeTransformerOptions {
4
- classActivePre?: string;
5
- classActiveLine?: string;
6
- }
7
- export declare const createTransformerCallouts: (options?: ITransformerCalloutsOptions) => Exclude<PluginShikiOptions["transformers"], undefined>[0];
@@ -1,16 +0,0 @@
1
- import { addClass, checkClass, createRangeTransformer } from '../utils.js';
2
- export const createTransformerCallouts = (options = {}) => {
3
- const { classActiveLine = 'callout', classActivePre = 'has-callouts' } = options;
4
- return {
5
- name: 'shiki-transformer:callouts',
6
- preTransformer: createRangeTransformer({
7
- callout: classActiveLine,
8
- }, options),
9
- postTransformer({ code }) {
10
- if (!checkClass(code, classActiveLine)) {
11
- return code;
12
- }
13
- return addClass(code, classActivePre, 'pre');
14
- },
15
- };
16
- };
@@ -1 +0,0 @@
1
- export * from './callouts.js';
@@ -1 +0,0 @@
1
- export * from './callouts.js';
@@ -1,14 +0,0 @@
1
- import type { HtmlRendererOptions } from 'shiki';
2
- export type TLineOptions = NonNullable<HtmlRendererOptions['lineOptions']>;
3
- export interface ITransformerResult {
4
- code: string;
5
- lineOptions: TLineOptions;
6
- }
7
- export interface ITransformerOptions {
8
- code: string;
9
- lang: string;
10
- }
11
- export type TPreTransformer = (options: ITransformerOptions) => ITransformerResult;
12
- export interface IRangeTransformerOptions {
13
- tagRegExp?: RegExp;
14
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import type { IRangeTransformerOptions, TPreTransformer } from './types.js';
2
- export declare function createRangeTransformer(classMap: Record<string, string | string[]>, options?: IRangeTransformerOptions): TPreTransformer;
3
- export declare const checkClass: (code: string, className: string | string[]) => boolean;
4
- export declare function addClass(code: string, classes: string | string[], tag?: string): string;
@@ -1,47 +0,0 @@
1
- export function createRangeTransformer(classMap, options = {}) {
2
- return ({ code }) => {
3
- // https://regex101.com/r/mUxvfx/1
4
- const tagRE = options.tagRegExp ??
5
- /(?:#|\/\/|\/\*{1,2}) *\[!code ([\w+-]+)(?::(\d+))?] *(?:\*{1,2}\/)?/;
6
- const lineOptions = [];
7
- const tags = Object.keys(classMap);
8
- const codeFormat = code
9
- .split('\n')
10
- .map((lineOfCode, lineNumber) => {
11
- const [match, tag, range] = lineOfCode.match(tagRE) ?? [];
12
- if (!match) {
13
- return lineOfCode;
14
- }
15
- if (!tags.includes(tag)) {
16
- return lineOfCode;
17
- }
18
- for (const [rangeOffset] of Array.from({
19
- length: Number(range ?? 1),
20
- }).entries()) {
21
- lineOptions.push({
22
- line: lineNumber + rangeOffset + 1,
23
- classes: typeof classMap[tag] === 'string'
24
- ? [classMap[tag]]
25
- : classMap[tag],
26
- });
27
- }
28
- return lineOfCode.replace(tagRE, '');
29
- })
30
- .join('\n');
31
- return {
32
- code: codeFormat,
33
- lineOptions,
34
- };
35
- };
36
- }
37
- export const checkClass = (code, className) => {
38
- const classes = Array.isArray(className) ? className.join(' ') : className;
39
- return code.search(classes) !== -1;
40
- };
41
- export function addClass(code, classes, tag) {
42
- const classRE = new RegExp(`<${tag ?? 'w+'}[^>]*class="([\\w+-:;\\/* ]*)"`);
43
- classes = Array.isArray(classes) ? classes : [classes];
44
- return code.replace(classRE, (match, previousClasses) => {
45
- return match.replace(previousClasses, `${previousClasses} ${classes.join(' ')}`.trim());
46
- });
47
- }
@@ -1,2 +0,0 @@
1
- import type { RspressPlugin } from '@rspress/core';
2
- export declare const swaggerPlugin: () => RspressPlugin;
@@ -1,38 +0,0 @@
1
- import path from 'node:path';
2
- import { glob } from 'tinyglobby';
3
- import { resolveStaticConfig } from '../../utils/index.js';
4
- const crdMap = {};
5
- const openapiMap = {};
6
- let allModelReferences;
7
- export const swaggerPlugin = () => {
8
- return {
9
- name: 'doom-swagger',
10
- async beforeBuild(config_) {
11
- const config = config_;
12
- if (!config.swagger) {
13
- return;
14
- }
15
- const { crds, openapis, modelReferences } = config.swagger;
16
- if (crds) {
17
- for (const file of await glob(crds, {
18
- cwd: config.root,
19
- })) {
20
- crdMap[file] = await resolveStaticConfig(path.resolve(config.root, file));
21
- }
22
- }
23
- if (openapis) {
24
- for (const file of await glob(openapis, {
25
- cwd: config.root,
26
- })) {
27
- openapiMap[file] = await resolveStaticConfig(path.resolve(config.root, file));
28
- }
29
- }
30
- allModelReferences = modelReferences;
31
- },
32
- extendPageData(pageData) {
33
- pageData.crdMap = crdMap;
34
- pageData.openapiMap = openapiMap;
35
- pageData.modelReferences = allModelReferences;
36
- },
37
- };
38
- };
@@ -1,28 +0,0 @@
1
- import { OpenAPIV3 } from 'openapi-types';
2
- export interface CustomResourceDefinitionVersion {
3
- name: string;
4
- schema: {
5
- openAPIV3Schema: OpenAPIV3.SchemaObject;
6
- };
7
- served: boolean;
8
- storage: boolean;
9
- }
10
- export interface CustomResourceDefinition {
11
- apiVersion: string;
12
- kind: 'CustomResourceDefinition';
13
- metadata: {
14
- annotations: Record<string, string>;
15
- name: string;
16
- };
17
- spec: {
18
- group: string;
19
- names: {
20
- kind: string;
21
- listKind: string;
22
- plural: string;
23
- singular: string;
24
- };
25
- scope: 'Namespaced' | 'Cluster';
26
- versions: CustomResourceDefinitionVersion[];
27
- };
28
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export interface SwaggerModelProps {
2
- model: string;
3
- }
4
- export declare const SwaggerModel: ({ model }: SwaggerModelProps) => import("react/jsx-runtime").JSX.Element;
5
- export default SwaggerModel;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- export const SwaggerModel = ({ model }) => {
3
- return _jsx("h2", { children: model });
4
- };
5
- export default SwaggerModel;
@@ -1,5 +0,0 @@
1
- export interface SwaggerPathProps {
2
- path: string;
3
- }
4
- export declare const SwaggerPath: ({ path }: SwaggerPathProps) => import("react/jsx-runtime").JSX.Element | null;
5
- export default SwaggerPath;
@@ -1,32 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { usePageData } from '@rspress/core/runtime';
3
- import { getCustomMDXComponent } from '@rspress/core/theme';
4
- import { OpenAPIV3 } from 'openapi-types';
5
- import { useMemo } from 'react';
6
- import { HeadingTitle } from './_HeadingTitle.js';
7
- export const SwaggerPath = ({ path }) => {
8
- const X = useMemo(getCustomMDXComponent, []);
9
- const { page } = usePageData();
10
- const pathItem = useMemo(() => {
11
- for (const [, openapi] of Object.entries(page.openapiMap || {})) {
12
- const pathItem = openapi.paths?.[path];
13
- if (pathItem) {
14
- return pathItem;
15
- }
16
- }
17
- }, [page.openapiMap]);
18
- if (!pathItem) {
19
- console.error(`No OpenAPI path definition found for ${path}`);
20
- return null;
21
- }
22
- return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { level: 2, children: path }), Object.values(OpenAPIV3.HttpMethods).map((method) => {
23
- if (!pathItem[method]) {
24
- return null;
25
- }
26
- const { parameters, summary } = pathItem[method];
27
- return (_jsxs(_Fragment, { children: [_jsxs(HeadingTitle, { level: 3, children: [_jsx(X.code, { children: method }), summary] }), _jsx(HeadingTitle, { level: 4, children: "Parameters" }), _jsx(X.ul, { children: parameters?.map((parameter, index) => {
28
- return (_jsxs(X.li, { children: [_jsx(X.code, { children: parameter.name }), parameter.description] }, index));
29
- }) })] }));
30
- })] }));
31
- };
32
- export default SwaggerPath;
File without changes