@alauda/doom 0.8.4 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ import { normalizeVersion } from '../shared/index.js';
10
10
  import { pkgResolve, resolveStaticConfig, } from '../utils/index.js';
11
11
  import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
12
12
  import { replacePlugin } from '../plugins/replace/index.js';
13
+ import { mermaidPlugin } from '../plugins/mermaid/index.js';
13
14
  const DEFAULT_LOGO = '/logo.svg';
14
15
  const zhLocaleConfig = {
15
16
  searchPlaceholderText: '搜索文档',
@@ -73,6 +74,7 @@ const getCommonConfig = (config, cliRoot, configFilePath, version, ignore, force
73
74
  sites: config.sites,
74
75
  version,
75
76
  }),
77
+ mermaidPlugin(),
76
78
  replacePlugin({
77
79
  root,
78
80
  lang: fallbackToZh ? null : (config.lang ?? 'en'),
@@ -82,16 +84,26 @@ const getCommonConfig = (config, cliRoot, configFilePath, version, ignore, force
82
84
  releaseNotes: config.releaseNotes,
83
85
  }),
84
86
  shikiPlugin({
85
- langs: ['dockerfile', 'html', 'go', 'jsonc'],
87
+ langs: ['dockerfile', 'html', 'go', 'jsonc', 'mermaid'],
86
88
  transformers: [
87
89
  // builtin transformers
88
90
  transformerMetaHighlight(),
89
91
  transformerMetaWordHighlight(),
90
- transformerNotationDiff(),
91
- transformerNotationErrorLevel(),
92
- transformerNotationFocus(),
93
- transformerNotationHighlight(),
94
- transformerNotationWordHighlight(),
92
+ transformerNotationDiff({
93
+ matchAlgorithm: 'v3',
94
+ }),
95
+ transformerNotationErrorLevel({
96
+ matchAlgorithm: 'v3',
97
+ }),
98
+ transformerNotationFocus({
99
+ matchAlgorithm: 'v3',
100
+ }),
101
+ transformerNotationHighlight({
102
+ matchAlgorithm: 'v3',
103
+ }),
104
+ transformerNotationWordHighlight({
105
+ matchAlgorithm: 'v3',
106
+ }),
95
107
  transformerRemoveNotationEscape(),
96
108
  // custom transformers
97
109
  createTransformerCallouts(),
@@ -5,7 +5,12 @@ 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
- const getNavMenu = () => document.querySelector('.rspress-nav-menu');
8
+ const getNavMenu = () => {
9
+ if (typeof document === 'undefined') {
10
+ return null;
11
+ }
12
+ return document.querySelector('.rspress-nav-menu');
13
+ };
9
14
  export const VersionsNav = () => {
10
15
  const { siteData, page } = usePageData();
11
16
  const [versionsBase, version] = useMemo(() => {
@@ -1,4 +1,4 @@
1
- import type { RspressPlugin } from '@rspress/core';
1
+ import { type RspressPlugin } from '@rspress/core';
2
2
  import type { DoomSite } from '../../shared/types.js';
3
3
  export interface GlobalPluginOptions {
4
4
  sites?: DoomSite[];
@@ -1,6 +1,8 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { addTrailingSlash } from '@rspress/core';
3
4
  import { baseResolve, pkgResolve } from '../../utils/index.js';
5
+ import { normalizeVersion } from '../../shared/helpers.js';
4
6
  const globalComponentsDir = baseResolve('global');
5
7
  const componentsDir = baseResolve('runtime/components');
6
8
  export const globalPlugin = ({ sites, version, } = {}) => {
@@ -22,7 +24,11 @@ export const globalPlugin = ({ sites, version, } = {}) => {
22
24
  .map((file) => path.resolve(componentsDir, file)),
23
25
  },
24
26
  extendPageData(pageData) {
25
- pageData.sites = sites;
27
+ pageData.sites = sites?.map((site) => ({
28
+ ...site,
29
+ base: addTrailingSlash(site.base || (site.name === 'acp' ? '/container-platform' : '')),
30
+ version: normalizeVersion(site.version),
31
+ }));
26
32
  pageData.v = version === 'unversioned' ? undefined : version;
27
33
  },
28
34
  };
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from '@rspress/core';
2
+ export declare const mermaidPlugin: () => Plugin;
@@ -0,0 +1,9 @@
1
+ import { remarkMermaid } from './remark-mermaid.js';
2
+ export const mermaidPlugin = () => {
3
+ return {
4
+ name: 'doom-mermaid',
5
+ markdown: {
6
+ remarkPlugins: [remarkMermaid],
7
+ },
8
+ };
9
+ };
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'unified';
2
+ import type { Root } from 'mdast';
3
+ export declare const remarkMermaid: Plugin<[], Root>;
@@ -0,0 +1,22 @@
1
+ import { visit } from 'unist-util-visit';
2
+ export const remarkMermaid = function () {
3
+ return (root) => {
4
+ visit(root, 'code', (node, index, parent) => {
5
+ if (!parent || node.lang !== 'mermaid') {
6
+ return;
7
+ }
8
+ parent.children.splice(index, 1, {
9
+ type: 'mdxJsxFlowElement',
10
+ name: 'Mermaid',
11
+ attributes: [
12
+ {
13
+ type: 'mdxJsxAttribute',
14
+ name: 'children',
15
+ value: node.value,
16
+ },
17
+ ],
18
+ children: [],
19
+ });
20
+ });
21
+ };
22
+ };
@@ -6,5 +6,6 @@ export const createTransformerCallouts = (options = {}) => {
6
6
  callout: classActiveLine,
7
7
  },
8
8
  classActivePre,
9
+ matchAlgorithm: 'v3',
9
10
  }, 'shiki-transformer:callouts');
10
11
  };
@@ -3,7 +3,6 @@ import { useLang, usePageData } 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
- import { normalizeVersion } from '../../shared/index.js';
7
6
  import { Directive } from './Directive.js';
8
7
  import classes from '../../../styles/link.module.scss';
9
8
  export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
@@ -16,10 +15,7 @@ export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
16
15
  if (isExternalUrl(href)) {
17
16
  return _jsxs(Directive, { type: "danger", children: ["Invalid href `", href, "` found"] });
18
17
  }
19
- const siteBase = addTrailingSlash(site.base || (site.name === 'acp' ? '/container-platform' : ''));
20
- return (_jsx("a", { href: (page.v
21
- ? addTrailingSlash(siteBase + normalizeVersion(site.version))
22
- : siteBase) +
18
+ return (_jsx("a", { href: (page.v ? addTrailingSlash(site.base + site.version) : site.base) +
23
19
  (lang ? `${lang}/` : '') +
24
20
  removeLeadingSlash(href), target: "_blank", rel: "noopener noreferrer", className: clsx(classes.link, 'cursor-pointer', className), ...props }));
25
21
  };
@@ -0,0 +1,7 @@
1
+ import type { FC } from 'react';
2
+ export interface MermaidProps {
3
+ className?: string;
4
+ children: string;
5
+ }
6
+ export declare const Mermaid: FC<MermaidProps>;
7
+ export default Mermaid;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useDark } from '@rspress/core/runtime';
3
+ import clsx from 'clsx';
4
+ import mermaid from 'mermaid';
5
+ import { useEffect, useId, useRef } from 'react';
6
+ export const Mermaid = ({ className, children }) => {
7
+ const id = useId();
8
+ const isDark = useDark();
9
+ const containerRef = useRef(null);
10
+ useEffect(() => {
11
+ const container = containerRef.current;
12
+ mermaid.initialize({ theme: isDark ? 'dark' : 'default' });
13
+ const render = async () => {
14
+ const { svg, diagramType, bindFunctions } = await mermaid.render(`mermaid-${id.slice(1, -1)}`, children);
15
+ container.classList.add(diagramType);
16
+ container.innerHTML = svg;
17
+ bindFunctions?.(container);
18
+ };
19
+ void render();
20
+ }, [children, isDark]);
21
+ return (_jsx("div", { ref: containerRef, id: id, className: clsx('doom-mermaid', className) }));
22
+ };
23
+ export default Mermaid;
@@ -1,6 +1,7 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useSiteOverrides } from '../hooks/index.js';
3
+ import { handleCJKWhitespaces } from '../utils.js';
3
4
  export const BrandBase = ({ type }) => {
4
5
  const { brand } = useSiteOverrides();
5
- return _jsx(_Fragment, { children: brand?.[type] });
6
+ return _jsx(_Fragment, { children: handleCJKWhitespaces(brand?.[type]) });
6
7
  };
@@ -10,6 +10,7 @@ export * from './ExternalSiteLink.js';
10
10
  export * from './JsonViewer.js';
11
11
  export * from './K8sCrd.js';
12
12
  export * from './LinkCard.js';
13
+ export * from './Mermaid.js';
13
14
  export * from './Overview.js';
14
15
  export * from './OpenAPIRef.js';
15
16
  export * from './OpenAPIPath.js';
@@ -10,6 +10,7 @@ export * from './ExternalSiteLink.js';
10
10
  export * from './JsonViewer.js';
11
11
  export * from './K8sCrd.js';
12
12
  export * from './LinkCard.js';
13
+ export * from './Mermaid.js';
13
14
  export * from './Overview.js';
14
15
  export * from './OpenAPIRef.js';
15
16
  export * from './OpenAPIPath.js';
@@ -1,16 +1,26 @@
1
- import { addTrailingSlash } from '@rspress/shared';
2
1
  import { isProduction, useLang, usePageData } from '@rspress/core/runtime';
3
2
  import { useEffect, useMemo, useState } from 'react';
4
3
  import { parse } from 'yaml';
5
- import { normalizeVersion } from '../../shared/helpers.js';
4
+ const DEFAULT_SITE_BRAND = {
5
+ en: {
6
+ company: 'Alauda',
7
+ product: 'Alauda Container Platform',
8
+ productShort: 'ACP',
9
+ },
10
+ zh: {
11
+ company: '灵雀云',
12
+ product: '灵雀云容器平台',
13
+ productShort: 'ACP',
14
+ },
15
+ };
6
16
  let siteOverrides;
7
17
  let promise;
8
18
  const fetchSiteOverrides = async (base, version, acpSite) => {
9
19
  if (promise) {
10
20
  return promise;
11
21
  }
12
- const acpSiteOverridesUrl = acpSite
13
- ? `${addTrailingSlash(acpSite.base || '/container-platform')}${version ? normalizeVersion(acpSite.version) + '/' : ''}overrides.yaml`
22
+ const acpSiteOverridesUrl = acpSite && isProduction()
23
+ ? `${acpSite.base}${version ? acpSite.version + '/' : ''}overrides.yaml`
14
24
  : null;
15
25
  const siteOverridesUrl = `${isProduction() ? base : '/'}overrides.yaml`;
16
26
  const urls = [acpSiteOverridesUrl];
@@ -32,7 +42,7 @@ const fetchSiteOverrides = async (base, version, acpSite) => {
32
42
  //
33
43
  }
34
44
  })).then(([acpSiteOverrides, siteOverrides]) => (siteOverrides = {
35
- brand: acpSiteOverrides?.brand,
45
+ brand: acpSiteOverrides?.brand ?? DEFAULT_SITE_BRAND,
36
46
  ...siteOverrides,
37
47
  }))).catch(() => ({}));
38
48
  };
@@ -8,4 +8,4 @@ export declare const omitRoutePathRefs: (refs: Record<string, string>, routePath
8
8
  [k: string]: string;
9
9
  };
10
10
  export declare const CJK_PATTERN: RegExp;
11
- export declare const handleCJKWhitespaces: (text: string) => string;
11
+ export declare const handleCJKWhitespaces: (text?: string) => string;
@@ -19,6 +19,9 @@ export const DEFAULT_COMMON_REFS = Object.fromEntries(Object.entries(DEFAULT_COM
19
19
  export const omitRoutePathRefs = (refs, routePath) => Object.fromEntries(Object.entries(refs).filter(([, value]) => routePath !== value.split('#')[0]));
20
20
  export const CJK_PATTERN = /\p{sc=Han}/u;
21
21
  export const handleCJKWhitespaces = (text) => {
22
+ if (!text) {
23
+ return '';
24
+ }
22
25
  text = text.at(0)?.match(CJK_PATTERN) ? text : ` ${text}`;
23
26
  return text.at(-1)?.match(CJK_PATTERN) ? text : `${text} `;
24
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.8.4",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -41,12 +41,13 @@
41
41
  "@inquirer/prompts": "^7.2.3",
42
42
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
43
43
  "@rspress/core": "1.40.0",
44
- "@shikijs/transformers": "^1.27.2",
44
+ "@shikijs/transformers": "^2.1.0",
45
45
  "chokidar": "^4.0.3",
46
46
  "clsx": "^2.1.1",
47
- "commander": "^12.1.0",
47
+ "commander": "^13.1.0",
48
48
  "ejs": "^3.1.10",
49
49
  "es-toolkit": "^1.31.0",
50
+ "mermaid": "^11.4.1",
50
51
  "openapi-types": "^12.1.3",
51
52
  "picomatch": "^4.0.2",
52
53
  "react-markdown": "^8.0.7",
@@ -54,34 +55,34 @@
54
55
  "remark-directive": "^2.0.1",
55
56
  "remark-frontmatter": "^4.0.1",
56
57
  "remark-gfm": "^3.0.1",
57
- "shiki": "^1.27.2",
58
+ "shiki": "^2.1.0",
58
59
  "simple-git": "^3.27.0",
59
60
  "swagger2openapi": "^7.0.8",
60
61
  "tinyglobby": "^0.2.10",
61
- "type-fest": "^4.32.0",
62
+ "type-fest": "^4.33.0",
62
63
  "yaml": "^2.7.0",
63
64
  "yoctocolors": "^2.1.1"
64
65
  },
65
66
  "devDependencies": {
66
67
  "@eslint/js": "^9.18.0",
67
68
  "@swc-node/register": "^1.10.9",
68
- "@swc/core": "1.10.7",
69
+ "@swc/core": "1.10.9",
69
70
  "@types/ejs": "^3.1.5",
70
71
  "@types/eslint__js": "^8.42.3",
71
72
  "@types/fs-extra": "^11.0.4",
72
73
  "@types/node": "^18.19.71",
73
- "@types/picomatch": "^3.0.1",
74
+ "@types/picomatch": "^3.0.2",
74
75
  "@types/react-dom": "^18.3.5",
75
76
  "@types/swagger2openapi": "^7.0.4",
76
77
  "@unts/patch-package": "^8.0.0",
77
78
  "eslint": "^9.18.0",
78
- "lint-staged": "^15.4.0",
79
+ "lint-staged": "^15.4.1",
79
80
  "npm-run-all2": "^7.0.2",
80
81
  "prettier": "^3.4.2",
81
82
  "prettier-plugin-pkg": "^0.18.1",
82
83
  "simple-git-hooks": "^2.11.1",
83
84
  "typescript": "^5.7.3",
84
- "typescript-eslint": "^8.20.0"
85
+ "typescript-eslint": "^8.21.0"
85
86
  },
86
87
  "publishConfig": {
87
88
  "access": "public"