@alauda/doom 0.4.0 → 0.4.2

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 (56) 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 +19 -10
  4. package/lib/cli/load-config.d.ts +2 -2
  5. package/lib/cli/load-config.js +27 -14
  6. package/lib/global/VersionsNav/Down.d.ts +1 -0
  7. package/lib/global/VersionsNav/Down.js +2 -0
  8. package/lib/global/VersionsNav/NavMenuGroup.d.ts +12 -0
  9. package/lib/global/VersionsNav/NavMenuGroup.js +53 -0
  10. package/lib/global/VersionsNav/NavMenuSingleItem.d.ts +10 -0
  11. package/lib/global/VersionsNav/NavMenuSingleItem.js +9 -0
  12. package/lib/global/VersionsNav/SvgWrapper.d.ts +7 -0
  13. package/lib/global/VersionsNav/SvgWrapper.js +14 -0
  14. package/lib/global/VersionsNav/index.d.ts +2 -0
  15. package/lib/global/VersionsNav/index.js +58 -0
  16. package/lib/plugins/api/index.js +3 -3
  17. package/lib/plugins/global/index.d.ts +1 -1
  18. package/lib/plugins/global/index.js +10 -1
  19. package/lib/runtime/components/Badge.d.ts +1 -1
  20. package/lib/runtime/components/Badge.js +1 -1
  21. package/lib/runtime/components/Card.d.ts +1 -1
  22. package/lib/runtime/components/Card.js +1 -1
  23. package/lib/runtime/components/ExternalSite.d.ts +9 -0
  24. package/lib/runtime/components/ExternalSite.js +32 -0
  25. package/lib/runtime/components/JsonViewer.d.ts +6 -0
  26. package/lib/runtime/components/JsonViewer.js +8 -0
  27. package/lib/runtime/components/K8sCrd.js +1 -1
  28. package/lib/runtime/components/LinkCard.d.ts +1 -1
  29. package/lib/runtime/components/LinkCard.js +1 -1
  30. package/lib/runtime/components/OpenAPIRef.js +1 -1
  31. package/lib/runtime/components/PackageManagerTabs.d.ts +1 -1
  32. package/lib/runtime/components/PackageManagerTabs.js +1 -1
  33. package/lib/runtime/components/Steps.d.ts +1 -1
  34. package/lib/runtime/components/Steps.js +1 -1
  35. package/lib/runtime/components/Tab.d.ts +1 -1
  36. package/lib/runtime/components/Tab.js +1 -1
  37. package/lib/runtime/components/Tabs.d.ts +1 -1
  38. package/lib/runtime/components/Tabs.js +1 -1
  39. package/lib/runtime/components/Toc.d.ts +1 -1
  40. package/lib/runtime/components/Toc.js +1 -1
  41. package/lib/runtime/components/_Directive.d.ts +10 -0
  42. package/lib/runtime/components/_Directive.js +16 -0
  43. package/lib/runtime/components/index.d.ts +3 -1
  44. package/lib/runtime/components/index.js +3 -1
  45. package/lib/runtime/types.d.ts +3 -0
  46. package/lib/runtime/utils.d.ts +2 -0
  47. package/lib/runtime/utils.js +5 -0
  48. package/lib/shared/helpers.d.ts +1 -0
  49. package/lib/shared/helpers.js +2 -0
  50. package/lib/shared/index.d.ts +2 -0
  51. package/lib/shared/index.js +2 -0
  52. package/lib/shared/types.d.ts +7 -0
  53. package/lib/shared/types.js +1 -0
  54. package/lib/utils/types.d.ts +2 -0
  55. package/package.json +3 -1
  56. package/styles/versions-nav.module.scss +11 -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
@@ -9,10 +9,10 @@ import { build, dev, serve } from '@rspress/core';
9
9
  import { watch } from 'chokidar';
10
10
  import { program } from 'commander';
11
11
  import { green } from 'yoctocolors';
12
- import { CWD, DEFAULT_CONFIGS, I18N_FILE } from './constants.js';
12
+ import { CWD, DEFAULT_CONFIGS, I18N_FILE, SITES_FILE } from './constants.js';
13
13
  import { loadConfig } from './load-config.js';
14
14
  const META_FILE = '_meta.json';
15
- const CONFIG_FILES = [...DEFAULT_CONFIGS, I18N_FILE];
15
+ const CONFIG_FILES = [...DEFAULT_CONFIGS, I18N_FILE, SITES_FILE];
16
16
  const setNodeEnv = (env) => {
17
17
  process.env.NODE_ENV = env;
18
18
  };
@@ -22,18 +22,23 @@ program
22
22
  .name('doom')
23
23
  .description(pkg.description)
24
24
  .version(pkg.version)
25
+ .configureHelp({
26
+ showGlobalOptions: true,
27
+ })
25
28
  .option('-c, --config [config]', 'Specify the path to the config file')
29
+ .option('-v <version>', 'Specify the version of the documentation')
26
30
  .command('dev', { isDefault: true })
27
31
  .description('Start the development server')
28
32
  .argument('[root]', 'Root directory of the documentation')
29
33
  .option('--port [port]', 'Port number')
30
34
  .option('--host [host]', 'Host name')
31
- .action(async (root, { config: configFile, ...server }) => {
35
+ .action(async function (root) {
32
36
  setNodeEnv('development');
33
37
  let devServer;
34
38
  let cliWatcher;
39
+ const { config: configFile, v: version, ...server } = this.optsWithGlobals();
35
40
  const startDevServer = async () => {
36
- const { config, filepath } = await loadConfig(root, configFile);
41
+ const { config, filepath } = await loadConfig(root, configFile, version);
37
42
  const docDirectory = config.root;
38
43
  try {
39
44
  devServer = await dev({
@@ -50,7 +55,7 @@ program
50
55
  devServer = undefined;
51
56
  }
52
57
  cliWatcher = watch(filepath
53
- ? [filepath, docDirectory, config.i18nSourcePath]
58
+ ? [filepath, config.i18nSourcePath, docDirectory, SITES_FILE]
54
59
  : [...CONFIG_FILES, docDirectory], {
55
60
  ignoreInitial: true,
56
61
  ignored: ['**/node_modules/**', '**/.git/**', '**/.DS_Store/**'],
@@ -58,6 +63,7 @@ program
58
63
  });
59
64
  let isRestarting = false;
60
65
  cliWatcher.on('all', async (eventName, filepath) => {
66
+ console.log(eventName, filepath);
61
67
  if (eventName === 'add' ||
62
68
  eventName === 'unlink' ||
63
69
  (eventName === 'change' &&
@@ -89,11 +95,13 @@ program
89
95
  process.on('SIGINT', exitProcess);
90
96
  process.on('SIGTERM', exitProcess);
91
97
  })
92
- .parent.command('build [root]')
98
+ .parent.command('build')
93
99
  .description('Build the documentation')
94
- .action(async (root, { config: configFile }) => {
100
+ .argument('[root]', 'Root directory of the documentation')
101
+ .action(async function (root) {
95
102
  setNodeEnv('production');
96
- const { config } = await loadConfig(root, configFile);
103
+ const { config: configFile, v: version } = this.optsWithGlobals();
104
+ const { config } = await loadConfig(root, configFile, version);
97
105
  const docDirectory = config.root;
98
106
  await build({
99
107
  config,
@@ -107,9 +115,10 @@ program
107
115
  .argument('[root]', 'Root directory of the documentation')
108
116
  .option('--port [port]', 'Port number', '4173')
109
117
  .option('--host [host]', 'Host name')
110
- .action(async (root, { config: configFile, ...server }) => {
118
+ .action(async function (root) {
111
119
  setNodeEnv('production');
112
- const { config } = await loadConfig(root, configFile);
120
+ const { config: configFile, v: version, ...server } = this.optsWithGlobals();
121
+ const { config } = await loadConfig(root, configFile, version);
113
122
  await serve({
114
123
  config,
115
124
  ...server,
@@ -1,5 +1,5 @@
1
- import { DoomConfig } from '../utils/types.js';
2
- export declare function loadConfig(root?: string, configFile?: string): Promise<{
1
+ import { type DoomConfig } from '../utils/index.js';
2
+ export declare function loadConfig(root?: string, configFile?: string, version?: string): Promise<{
3
3
  config: DoomConfig;
4
4
  filepath?: string;
5
5
  }>;
@@ -1,16 +1,16 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { nodeTypes } from '@mdx-js/mdx';
4
- import { addLeadingSlash, addTrailingSlash, removeLeadingSlash, } from '@rspress/core';
4
+ import { addLeadingSlash, addTrailingSlash, removeLeadingSlash, removeTrailingSlash, } from '@rspress/core';
5
5
  import { pluginPreview } from '@rspress/plugin-preview';
6
6
  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 { normalizeVersion } from '../shared/index.js';
12
+ import { pkgResolve, resolveStaticConfig, } from '../utils/index.js';
13
+ import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
14
14
  const DEFAULT_LOGO = '/logo.svg';
15
15
  const zhLocaleConfig = {
16
16
  searchPlaceholderText: '搜索文档',
@@ -20,7 +20,7 @@ const zhLocaleConfig = {
20
20
  prevPageText: '上一页',
21
21
  nextPageText: '下一页',
22
22
  };
23
- const getCommonConfig = async (config) => {
23
+ const getCommonConfig = async (config, version) => {
24
24
  const fallbackToZh = 'lang' in config && config.lang == null;
25
25
  return {
26
26
  lang: fallbackToZh ? 'zh' : config.lang,
@@ -63,9 +63,9 @@ const getCommonConfig = async (config) => {
63
63
  }),
64
64
  apiPlugin(),
65
65
  autoSidebarPlugin(),
66
- globalPlugin(),
66
+ globalPlugin(version),
67
67
  shikiPlugin({
68
- langs: ['dockerfile', 'go', 'jsonc'],
68
+ langs: ['dockerfile', 'html', 'go', 'jsonc'],
69
69
  transformers: [
70
70
  // builtin transformers
71
71
  transformerMetaHighlight(),
@@ -100,7 +100,7 @@ const getCommonConfig = async (config) => {
100
100
  const findConfig = (basePath) => {
101
101
  return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
102
102
  };
103
- export async function loadConfig(root, configFile) {
103
+ export async function loadConfig(root, configFile, version) {
104
104
  let configFilePath;
105
105
  if (configFile) {
106
106
  configFilePath = path.resolve(configFile);
@@ -125,7 +125,7 @@ export async function loadConfig(root, configFile) {
125
125
  else {
126
126
  try {
127
127
  if (YAML_EXTENSIONS.includes(path.extname(configFilePath))) {
128
- config = parse(fs.readFileSync(configFilePath, 'utf-8'));
128
+ config = await resolveStaticConfig(configFilePath);
129
129
  }
130
130
  else {
131
131
  const { content } = await loadConfig({
@@ -140,9 +140,22 @@ export async function loadConfig(root, configFile) {
140
140
  }
141
141
  }
142
142
  config ??= {};
143
- const mergedConfig = mergeRsbuildConfig(await getCommonConfig(config), config);
144
- const base = addLeadingSlash(mergedConfig.base || '/');
145
- mergedConfig.base = base;
143
+ if (config.sites) {
144
+ logger.error('Use separate `sites.yaml` config in repository root instead');
145
+ }
146
+ else {
147
+ const sitesConfigFilePath = path.resolve(SITES_FILE);
148
+ if (fs.existsSync(sitesConfigFilePath)) {
149
+ config.sites = await resolveStaticConfig(sitesConfigFilePath);
150
+ }
151
+ }
152
+ const normalizedVersion = normalizeVersion(version);
153
+ const mergedConfig = mergeRsbuildConfig(await getCommonConfig(config, normalizedVersion), config);
154
+ let base = addLeadingSlash(mergedConfig.base || '/');
155
+ if (normalizedVersion && normalizedVersion !== 'unversioned') {
156
+ base = removeTrailingSlash(base) + `/${normalizedVersion}`;
157
+ }
158
+ mergedConfig.base = base = addTrailingSlash(base);
146
159
  mergedConfig.root = resolveDocRoot(CWD, root, mergedConfig.root);
147
160
  let ensureDefaultLogo = false;
148
161
  if (!mergedConfig.logo) {
@@ -170,10 +183,10 @@ export async function loadConfig(root, configFile) {
170
183
  mergedConfig.i18nSourcePath = path.resolve(mergedConfig.root, I18N_FILE);
171
184
  }
172
185
  if (!mergedConfig.outDir) {
173
- mergedConfig.outDir = `dist${base}`;
186
+ mergedConfig.outDir = `dist${version === 'unversioned' ? `/unversioned${base}` : base}`;
174
187
  }
175
188
  if (mergedConfig.builderConfig?.server?.open === true) {
176
- mergedConfig.builderConfig.server.open = addTrailingSlash(base);
189
+ mergedConfig.builderConfig.server.open = base;
177
190
  }
178
191
  return {
179
192
  config: mergedConfig,
@@ -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,58 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { isProduction, 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, page } = usePageData();
10
+ const [versionsBase, version] = useMemo(() => {
11
+ if (!page.v) {
12
+ return [];
13
+ }
14
+ return [siteData.base.slice(0, -page.v.length - 1), page.v];
15
+ }, [siteData.base, page.v]);
16
+ const [navMenu, setNavMenu] = useState();
17
+ const [versions, setVersions] = useState();
18
+ useEffect(() => {
19
+ const fetchVersions = async () => {
20
+ if (versionsBase == null) {
21
+ return;
22
+ }
23
+ const res = await fetch(`${isProduction() ? versionsBase : ''}/versions.yaml`);
24
+ const text = await res.text();
25
+ setNavMenu(document.querySelector('.rspress-nav-menu'));
26
+ const versions = parse(text);
27
+ if (version && !versions.includes(version)) {
28
+ versions.unshift(version);
29
+ }
30
+ setVersions(versions);
31
+ };
32
+ fetchVersions().catch(noop);
33
+ }, []);
34
+ // hack way to detect nav menu recreation on theme change
35
+ useEffect(() => {
36
+ if (!navMenu) {
37
+ return;
38
+ }
39
+ const observer = new MutationObserver((mutations) => {
40
+ if (mutations.some((m) => m.removedNodes.length)) {
41
+ setNavMenu(document.querySelector('.rspress-nav-menu'));
42
+ }
43
+ });
44
+ observer.observe(navMenu, { childList: true });
45
+ return () => {
46
+ observer.disconnect();
47
+ };
48
+ }, [navMenu]);
49
+ if (!versions?.length) {
50
+ return null;
51
+ }
52
+ return createPortal(_jsx(NavMenuGroup, { text: version, base: versionsBase, items: versions.map((v) => ({
53
+ text: v,
54
+ link: `${versionsBase}/${v}/`,
55
+ activeMatch: v,
56
+ })), pathname: siteData.base }), document.querySelector('.rspress-nav-menu'));
57
+ };
58
+ 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_) {
@@ -1,2 +1,2 @@
1
1
  import type { RspressPlugin } from '@rspress/core';
2
- export declare const globalPlugin: () => RspressPlugin;
2
+ export declare const globalPlugin: (version?: string) => RspressPlugin;
@@ -2,10 +2,12 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { baseResolve, pkgResolve } from '../../utils/index.js';
4
4
  const componentsDir = baseResolve('runtime/components');
5
- export const globalPlugin = () => {
5
+ export const globalPlugin = (version) => {
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,12 @@ 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
+ pageData.v = version === 'unversioned' ? undefined : version;
28
+ },
20
29
  };
21
30
  };
@@ -1 +1 @@
1
- export { Badge, Badge as default } from '@rspress/theme-default';
1
+ export { Badge, Badge as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Badge, Badge as default } from '@rspress/theme-default';
1
+ export { Badge, Badge as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Card, Card as default } from '@rspress/theme-default';
1
+ export { Card, Card as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Card, Card as default } from '@rspress/theme-default';
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,32 @@
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 { normalizeVersion } from '../../shared/index.js';
6
+ import { handleCJKWhitespaces } from '../utils.js';
7
+ import { Directive } from './_Directive.js';
8
+ const Notes = {
9
+ en({ name, href }) {
10
+ 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 }), "."] }));
11
+ },
12
+ zh({ name, href }) {
13
+ const name_ = handleCJKWhitespaces(name);
14
+ 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"] }));
15
+ },
16
+ };
17
+ export const ExternalSite = ({ name }) => {
18
+ const { siteData, page } = usePageData();
19
+ const site = useMemo(() => page.sites?.find((s) => s.name === name), []);
20
+ const fallbackLang = siteData.lang || 'zh';
21
+ const lang = useLang() || fallbackLang;
22
+ const displayName = useMemo(() => site?.displayName?.[lang] || site?.displayName?.[fallbackLang] || name, []);
23
+ if (!site) {
24
+ return (_jsxs(Directive, { type: "danger", children: ["No site with name `", name, "` found, please ensure it's already defined at `sites.yaml`"] }));
25
+ }
26
+ const Note = Notes[lang] || Notes[fallbackLang] || Notes.en;
27
+ const siteBase = addTrailingSlash(site.base);
28
+ return (_jsx(Directive, { title: "Note", children: _jsx(Note, { name: displayName, href: page.v
29
+ ? addTrailingSlash(siteBase + normalizeVersion(site.defaultVersion))
30
+ : siteBase }) }));
31
+ };
32
+ export default ExternalSite;
@@ -0,0 +1,6 @@
1
+ import type { JsonValue } from 'type-fest';
2
+ export interface JsonViewerProps {
3
+ value: JsonValue;
4
+ }
5
+ export declare const JsonViewer: ({ value }: JsonViewerProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default JsonViewer;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { getCustomMDXComponent, Tab, Tabs } from '@rspress/core/theme';
3
+ import { stringify } from 'yaml';
4
+ const X = getCustomMDXComponent();
5
+ export const JsonViewer = ({ value }) => {
6
+ return (_jsxs(Tabs, { children: [_jsx(Tab, { label: "yaml", children: _jsx(X.pre, { children: _jsx(X.code, { className: "language-yaml", codeHighlighter: "prism", children: stringify(value) }) }) }), _jsx(Tab, { label: "json", children: _jsx(X.pre, { children: _jsx(X.code, { className: "language-json", codeHighlighter: "prism", children: JSON.stringify(value, null, 2) }) }) })] }));
7
+ };
8
+ export default JsonViewer;
@@ -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);
@@ -1 +1 @@
1
- export { LinkCard, LinkCard as default } from '@rspress/theme-default';
1
+ export { LinkCard, LinkCard as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { LinkCard, LinkCard as default } from '@rspress/theme-default';
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';
@@ -1 +1 @@
1
- export { PackageManagerTabs, PackageManagerTabs as default, } from '@rspress/theme-default';
1
+ export { PackageManagerTabs, PackageManagerTabs as default, } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { PackageManagerTabs, PackageManagerTabs as default, } from '@rspress/theme-default';
1
+ export { PackageManagerTabs, PackageManagerTabs as default, } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Steps, Steps as default } from '@rspress/theme-default';
1
+ export { Steps, Steps as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Steps, Steps as default } from '@rspress/theme-default';
1
+ export { Steps, Steps as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Tab, Tab as default } from '@rspress/theme-default';
1
+ export { Tab, Tab as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Tab, Tab as default } from '@rspress/theme-default';
1
+ export { Tab, Tab as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Tabs, Tabs as default } from '@rspress/theme-default';
1
+ export { Tabs, Tabs as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Tabs, Tabs as default } from '@rspress/theme-default';
1
+ export { Tabs, Tabs as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Toc, Toc as default } from '@rspress/theme-default';
1
+ export { Toc, Toc as default } from '@rspress/core/theme';
@@ -1 +1 @@
1
- export { Toc, Toc as default } from '@rspress/theme-default';
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,12 +1,14 @@
1
1
  export * from './Badge.js';
2
2
  export * from './Callouts.js';
3
3
  export * from './Card.js';
4
+ export * from './ExternalSite.js';
5
+ export * from './JsonViewer.js';
4
6
  export * from './K8sCrd.js';
5
7
  export * from './LinkCard.js';
6
8
  export * from './Overview.js';
7
- export * from './PackageManagerTabs.js';
8
9
  export * from './OpenAPIRef.js';
9
10
  export * from './OpenAPIPath.js';
11
+ export * from './PackageManagerTabs.js';
10
12
  export * from './QuickNav.js';
11
13
  export * from './Steps.js';
12
14
  export * from './Tab.js';
@@ -1,12 +1,14 @@
1
1
  export * from './Badge.js';
2
2
  export * from './Callouts.js';
3
3
  export * from './Card.js';
4
+ export * from './ExternalSite.js';
5
+ export * from './JsonViewer.js';
4
6
  export * from './K8sCrd.js';
5
7
  export * from './LinkCard.js';
6
8
  export * from './Overview.js';
7
- export * from './PackageManagerTabs.js';
8
9
  export * from './OpenAPIRef.js';
9
10
  export * from './OpenAPIPath.js';
11
+ export * from './PackageManagerTabs.js';
10
12
  export * from './QuickNav.js';
11
13
  export * from './Steps.js';
12
14
  export * from './Tab.js';
@@ -1,11 +1,14 @@
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 type { DoomSite } from '../shared/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[];
11
+ v?: string;
9
12
  }
10
13
  export interface ExtendedPageData extends PageData {
11
14
  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
+ };
@@ -0,0 +1 @@
1
+ export declare const normalizeVersion: (version?: string) => string;
@@ -0,0 +1,2 @@
1
+ const PLAIN_VERSION_PATTERN = /^(\d+\.)*\d+$/;
2
+ export const normalizeVersion = (version = '') => PLAIN_VERSION_PATTERN.test(version) ? `v${version}` : version;
@@ -0,0 +1,2 @@
1
+ export * from './helpers.js';
2
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ export * from './helpers.js';
2
+ export * from './types.js';
@@ -0,0 +1,7 @@
1
+ export interface DoomSite {
2
+ name: string;
3
+ displayName?: Record<string, string>;
4
+ repo: string;
5
+ base: string;
6
+ defaultVersion?: string;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  import { UserConfig } from '@rspress/core';
2
+ import { DoomSite } from '../shared/index.js';
2
3
  export interface DoomConfig extends UserConfig {
3
4
  api?: {
4
5
  crds?: string[];
@@ -6,4 +7,5 @@ export interface DoomConfig extends UserConfig {
6
7
  references?: Record<string, string>;
7
8
  pathPrefix?: string;
8
9
  };
10
+ sites?: DoomSite[];
9
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -54,6 +54,7 @@
54
54
  "shiki": "^1.24.3",
55
55
  "swagger2openapi": "^7.0.8",
56
56
  "tinyglobby": "^0.2.10",
57
+ "type-fest": "^4.30.2",
57
58
  "yaml": "^2.6.1",
58
59
  "yoctocolors": "^2.1.1"
59
60
  },
@@ -64,6 +65,7 @@
64
65
  "@types/eslint__js": "^8.42.3",
65
66
  "@types/fs-extra": "^11.0.4",
66
67
  "@types/node": "^18.19.68",
68
+ "@types/react-dom": "^18.3.5",
67
69
  "@types/swagger2openapi": "^7.0.4",
68
70
  "eslint": "^9.17.0",
69
71
  "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
+ }