@alauda/doom 0.13.3 → 0.14.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.
@@ -14,6 +14,6 @@ export declare function scanSideMeta(workDir: string, rootDir: string, docsDir:
14
14
  export declare function walk(workDir: string, routePrefix: string | undefined, docsDir: string, extensions: string[], excludeRoutes?: string[], collapsed?: boolean): Promise<{
15
15
  nav: never[];
16
16
  sidebar: {
17
- [x: string]: DoomSidebar[];
17
+ [routePrefix]: DoomSidebar[];
18
18
  };
19
19
  }>;
@@ -65,7 +65,7 @@ export const K8sPermissionTable = ({ functions }) => {
65
65
  (it) => it.metadata.annotations['auth.cpaas.io/role.id'],
66
66
  ]), []);
67
67
  const t = useTranslation();
68
- const lang = useLang() || 'zh';
68
+ const lang = useLang();
69
69
  const isZh = lang === 'zh';
70
70
  return (_jsxs(X.table, { children: [_jsx("thead", { children: _jsxs(X.tr, { children: [_jsx(X.th, { children: t('function') }), _jsx(X.th, { style: TEXT_NO_WRAP_STYLE, children: t('action') }), roleTemplates.map(({ metadata: { annotations, name } }) => (_jsx(X.th, { children: isZh
71
71
  ? annotations[DISPLAY_NAME_ZH]
@@ -0,0 +1,7 @@
1
+ import type { TermName } from '../../terms.js';
2
+ export interface TermProps {
3
+ name: TermName;
4
+ textCase?: 'lower' | 'upper' | 'capitalize';
5
+ }
6
+ export declare const Term: ({ name, textCase }: TermProps) => string;
7
+ export default Term;
@@ -0,0 +1,29 @@
1
+ import { capitalize } from 'es-toolkit';
2
+ import { useMemo } from 'react';
3
+ import { useSiteOverrides } from '../hooks/index.js';
4
+ import { handleCJKWhitespaces } from '../utils.js';
5
+ export const Term = ({ name, textCase }) => {
6
+ const { terms } = useSiteOverrides();
7
+ const text = useMemo(() => {
8
+ const origin = handleCJKWhitespaces(terms?.[name]);
9
+ if (!origin) {
10
+ return origin;
11
+ }
12
+ switch (textCase) {
13
+ case 'lower': {
14
+ return origin.toLowerCase();
15
+ }
16
+ case 'upper': {
17
+ return origin.toUpperCase();
18
+ }
19
+ case 'capitalize': {
20
+ return capitalize(origin);
21
+ }
22
+ default: {
23
+ return origin;
24
+ }
25
+ }
26
+ }, [terms, name, textCase]);
27
+ return text;
28
+ };
29
+ export default Term;
@@ -0,0 +1,5 @@
1
+ export interface TermsTableProps {
2
+ named?: boolean;
3
+ }
4
+ export declare const TermsTable: ({ named }: TermsTableProps) => import("react/jsx-runtime").JSX.Element;
5
+ export default TermsTable;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { useTranslation } from '../hooks/index.js';
4
+ import { getCustomMDXComponent } from '@rspress/core/theme';
5
+ import { allTermItems, namedTermItems, unnamedTermItems, } from '../../terms.js';
6
+ export const TermsTable = ({ named }) => {
7
+ const [X] = useState(getCustomMDXComponent);
8
+ const t = useTranslation();
9
+ const noNamed = named === false;
10
+ const terms = named
11
+ ? namedTermItems
12
+ : noNamed
13
+ ? unnamedTermItems
14
+ : allTermItems;
15
+ const renderBadCases = (list) => list?.length ? (_jsx(X.ul, { children: list.map((item, index) => (_jsx(X.li, { children: item }, index))) })) : ('-');
16
+ return (_jsxs(X.table, { children: [_jsx("thead", { children: _jsxs(X.tr, { children: [noNamed || _jsx(X.th, { children: t('name') }), _jsx(X.th, { children: t('chinese') }), _jsx(X.th, { children: t('chinese_bad_cases') }), _jsx(X.th, { children: t('english') }), _jsx(X.th, { children: t('english_bad_cases') }), _jsx(X.th, { children: t('description') })] }) }), _jsx("tbody", { children: terms.map((term, index) => (_jsxs(X.tr, { children: [noNamed || _jsx(X.td, { children: term.name || '-' }), _jsx(X.td, { children: term.zh || term.en }), _jsx(X.td, { children: renderBadCases(term.badCases?.zh) }), _jsx(X.td, { children: term.en }), _jsx(X.td, { children: renderBadCases(term.badCases?.en) }), _jsx(X.td, { children: term.description || '-' })] }, term.name || index))) })] }));
17
+ };
18
+ export default TermsTable;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useLang, usePageData } from '@rspress/core/runtime';
2
+ import { useLang } from '@rspress/core/runtime';
3
3
  import { useMemo } from 'react';
4
4
  import { handleCJKWhitespaces } from '../utils.js';
5
5
  import Directive from './Directive.js';
@@ -24,9 +24,8 @@ const ApisOverviewNotes = {
24
24
  },
25
25
  };
26
26
  export const ExternalSiteBase = ({ name, template }) => {
27
- const { siteData } = usePageData();
28
27
  const site = useMemo(() => virtual.sites?.find((s) => s.name === name), []);
29
- const lang = useLang() || siteData.lang || 'zh';
28
+ const lang = useLang();
30
29
  const displayName = useMemo(() => site?.displayName?.[lang] || site?.displayName?.en || name.toUpperCase(), []);
31
30
  if (!site) {
32
31
  return (_jsxs(Directive, { type: "danger", children: ["No site with name `", name, "` found, please ensure it's already defined at `sites.yaml`"] }));
@@ -2,7 +2,6 @@ export * from './AcpApisOverview.js';
2
2
  export * from './Badge.js';
3
3
  export * from './Callouts.js';
4
4
  export * from './Card.js';
5
- export * from './CompanyBrand.js';
6
5
  export * from './Directive.js';
7
6
  export * from './ExternalApisOverview.js';
8
7
  export * from './ExternalSite.js';
@@ -16,10 +15,10 @@ export * from './OpenAPIPath.js';
16
15
  export * from './OpenAPIRef.js';
17
16
  export * from './Overview.js';
18
17
  export * from './PackageManagerTabs.js';
19
- export * from './ProductBrand.js';
20
- export * from './ProductShortBrand.js';
21
18
  export * from './QuickNav.js';
22
19
  export * from './Steps.js';
23
20
  export * from './Tab.js';
24
21
  export * from './Tabs.js';
22
+ export * from './Term.js';
23
+ export * from './TermsTable.js';
25
24
  export * from './Toc.js';
@@ -2,7 +2,6 @@ export * from './AcpApisOverview.js';
2
2
  export * from './Badge.js';
3
3
  export * from './Callouts.js';
4
4
  export * from './Card.js';
5
- export * from './CompanyBrand.js';
6
5
  export * from './Directive.js';
7
6
  export * from './ExternalApisOverview.js';
8
7
  export * from './ExternalSite.js';
@@ -16,10 +15,10 @@ export * from './OpenAPIPath.js';
16
15
  export * from './OpenAPIRef.js';
17
16
  export * from './Overview.js';
18
17
  export * from './PackageManagerTabs.js';
19
- export * from './ProductBrand.js';
20
- export * from './ProductShortBrand.js';
21
18
  export * from './QuickNav.js';
22
19
  export * from './Steps.js';
23
20
  export * from './Tab.js';
24
21
  export * from './Tabs.js';
22
+ export * from './Term.js';
23
+ export * from './TermsTable.js';
25
24
  export * from './Toc.js';
@@ -1,10 +1,15 @@
1
- import type { SiteBrand } from '../types.js';
2
- export interface SiteOverrides {
3
- brand?: SiteBrand;
1
+ import { type NamedTerms, type TermName } from '../../terms.js';
2
+ import type { Locale } from '../translation.js';
3
+ export type SiteOverridesTerms = Record<TermName, string>;
4
+ export interface SiteOverridesItem {
4
5
  title?: string;
5
6
  logoText?: string;
7
+ terms?: SiteOverridesTerms;
6
8
  }
7
- export type SiteOverridesWithLangs = {
8
- [K in keyof SiteOverrides]: Record<string, SiteOverrides[K]>;
9
+ export type SiteOverrides = {
10
+ [K in Exclude<keyof SiteOverridesItem, 'terms'>]?: Partial<Record<Locale, SiteOverridesItem[K]>>;
11
+ } & {
12
+ terms?: NamedTerms;
9
13
  };
10
- export declare const useSiteOverrides: () => SiteOverrides;
14
+ export type NormalizedSiteOverrides = Record<Locale, SiteOverridesItem>;
15
+ export declare const useSiteOverrides: () => SiteOverridesItem;
@@ -1,20 +1,21 @@
1
- import { isProduction, useLang, usePageData } from '@rspress/core/runtime';
1
+ import { isProduction, usePageData } from '@rspress/core/runtime';
2
+ import { merge } from 'es-toolkit/compat';
2
3
  import { useEffect, useMemo, useState } from 'react';
3
4
  import { parse } from 'yaml';
5
+ import { namedTerms } from '../../terms.js';
6
+ import { useLocale } from './useTranslation.js';
4
7
  import virtual from 'doom-@global-virtual';
5
- const DEFAULT_SITE_BRAND = {
6
- en: {
7
- company: 'Alauda',
8
- product: 'Alauda Container Platform',
9
- productShort: 'ACP',
10
- },
11
- zh: {
12
- company: '灵雀云',
13
- product: '灵雀云容器平台',
14
- productShort: 'ACP',
15
- },
16
- };
17
- let siteOverrides;
8
+ const normalizeOverrides = (origin) => Object.keys(origin).reduce((acc, key_) => {
9
+ const key = key_;
10
+ const term = origin[key];
11
+ if (!term) {
12
+ return acc;
13
+ }
14
+ acc.en[key] = term.en;
15
+ acc.zh[key] = term.zh || acc.en[key];
16
+ return acc;
17
+ }, { en: {}, zh: {} });
18
+ let normalizedSiteOverrides;
18
19
  let promise;
19
20
  const fetchSiteOverrides = async (base, version, acpSite) => {
20
21
  if (promise) {
@@ -42,34 +43,31 @@ const fetchSiteOverrides = async (base, version, acpSite) => {
42
43
  catch {
43
44
  //
44
45
  }
45
- })).then(([acpSiteOverrides, siteOverrides]) => (siteOverrides = {
46
- brand: acpSiteOverrides?.brand ?? DEFAULT_SITE_BRAND,
46
+ }))
47
+ .then(([acpSiteOverrides, siteOverrides]) => ({
47
48
  ...siteOverrides,
48
- }))).catch(() => ({}));
49
+ terms: merge({}, namedTerms, acpSiteOverrides?.terms, siteOverrides?.terms),
50
+ }))
51
+ .catch(() => ({ terms: namedTerms }))
52
+ .then(({ terms, ...siteOverrides }) => {
53
+ const normalizedSiteOverrides = normalizeOverrides(siteOverrides);
54
+ const normalizedTerms = normalizeOverrides(terms);
55
+ return {
56
+ en: { ...normalizedSiteOverrides.en, terms: normalizedTerms.en },
57
+ zh: { ...normalizedSiteOverrides.zh, terms: normalizedTerms.zh },
58
+ };
59
+ }));
49
60
  };
50
61
  export const useSiteOverrides = () => {
51
62
  const { siteData } = usePageData();
52
- const [siteOverridesWithLangs, setSiteOverridesWithLangs] = useState(siteOverrides);
53
- const lang = useLang() || 'zh';
63
+ const [siteOverrides, setSiteOverrides] = useState(normalizedSiteOverrides);
64
+ const lang = useLocale();
54
65
  const acpSite = useMemo(() => virtual.sites?.find((s) => s.name === 'acp'), []);
55
66
  useEffect(() => {
56
- if (siteOverrides) {
67
+ if (normalizedSiteOverrides) {
57
68
  return;
58
69
  }
59
- void fetchSiteOverrides(siteData.base, virtual.version, acpSite).then(setSiteOverridesWithLangs);
70
+ void fetchSiteOverrides(siteData.base, virtual.version, acpSite).then(setSiteOverrides);
60
71
  }, []);
61
- return useMemo(() => {
62
- if (!siteOverridesWithLangs) {
63
- return {};
64
- }
65
- return Object.entries(siteOverridesWithLangs).reduce((acc, [key, value]) => {
66
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
67
- if (!value) {
68
- return acc;
69
- }
70
- // @ts-expect-error - don't waste time on typing
71
- acc[key] = value[lang] || value.en;
72
- return acc;
73
- }, {});
74
- }, [siteOverridesWithLangs, lang]);
72
+ return siteOverrides?.[lang] || {};
75
73
  };
@@ -1 +1,3 @@
1
- export declare const useTranslation: () => (key: "function" | "delete" | "create" | "update" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action") => string;
1
+ import { type Locale } from '../translation.js';
2
+ export declare const useLocale: () => Locale;
3
+ export declare const useTranslation: () => (key: "function" | "description" | "name" | "delete" | "create" | "update" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases") => string;
@@ -1,8 +1,9 @@
1
1
  import { useLang } from '@rspress/core/runtime';
2
2
  import { useCallback } from 'react';
3
3
  import { TRANSLATIONS } from '../translation.js';
4
+ export const useLocale = () => useLang();
4
5
  export const useTranslation = () => {
5
- const lang = (useLang() || 'zh');
6
+ const lang = useLocale();
6
7
  const translations = TRANSLATIONS[lang];
7
8
  return useCallback((key) => translations[key], []);
8
9
  };
@@ -1,5 +1,5 @@
1
1
  /// <reference path="../../global.d.ts" preserve="true" />
2
+ export * from '../terms.js';
2
3
  export * from './components/index.js';
3
4
  export * from './hooks/index.js';
4
- export * from './types.js';
5
5
  export * from './utils.js';
@@ -1,6 +1,6 @@
1
1
  // eslint-disable-next-line @typescript-eslint/triple-slash-reference
2
2
  /// <reference path="../../global.d.ts" preserve="true" />
3
+ export * from '../terms.js';
3
4
  export * from './components/index.js';
4
5
  export * from './hooks/index.js';
5
- export * from './types.js';
6
6
  export * from './utils.js';
@@ -9,6 +9,12 @@ export declare const TRANSLATIONS: {
9
9
  create: string;
10
10
  update: string;
11
11
  delete: string;
12
+ name: string;
13
+ chinese: string;
14
+ english: string;
15
+ description: string;
16
+ chinese_bad_cases: string;
17
+ english_bad_cases: string;
12
18
  };
13
19
  zh: {
14
20
  collapse_all: string;
@@ -20,6 +26,12 @@ export declare const TRANSLATIONS: {
20
26
  create: string;
21
27
  update: string;
22
28
  delete: string;
29
+ name: string;
30
+ chinese: string;
31
+ english: string;
32
+ description: string;
33
+ chinese_bad_cases: string;
34
+ english_bad_cases: string;
23
35
  };
24
36
  };
25
37
  export type Locale = keyof typeof TRANSLATIONS;
@@ -8,6 +8,12 @@ const en = {
8
8
  create: 'Create',
9
9
  update: 'Update',
10
10
  delete: 'Delete',
11
+ name: 'Name',
12
+ chinese: 'Chinese',
13
+ english: 'English',
14
+ description: 'Description',
15
+ chinese_bad_cases: 'Chinese Bad Cases',
16
+ english_bad_cases: 'English Bad Cases',
11
17
  };
12
18
  const zh = {
13
19
  collapse_all: '全部收起',
@@ -19,5 +25,11 @@ const zh = {
19
25
  create: '创建',
20
26
  update: '更新',
21
27
  delete: '删除',
28
+ name: '名称',
29
+ chinese: '中文',
30
+ english: '英文',
31
+ description: '描述',
32
+ chinese_bad_cases: '中文反例',
33
+ english_bad_cases: '英文反例',
22
34
  };
23
35
  export const TRANSLATIONS = { en, zh };
package/lib/terms.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ export interface TermItem {
2
+ en: string;
3
+ zh?: string;
4
+ description?: string;
5
+ badCases?: {
6
+ zh?: string[];
7
+ en?: string[];
8
+ };
9
+ }
10
+ export declare const unnamedTermItems: TermItem[];
11
+ declare const terms: {
12
+ readonly company: {
13
+ readonly en: "Alauda";
14
+ readonly zh: "灵雀云";
15
+ readonly description: "公司品牌";
16
+ };
17
+ readonly product: {
18
+ readonly en: "Alauda Container Platform";
19
+ readonly zh: "灵雀云容器平台";
20
+ readonly description: "产品品牌";
21
+ };
22
+ readonly productShort: {
23
+ readonly en: "ACP";
24
+ readonly description: "产品品牌简称";
25
+ };
26
+ };
27
+ export type TermName = keyof typeof terms;
28
+ export type NamedTerms = Record<TermName, TermItem>;
29
+ export interface NamedTermItem extends TermItem {
30
+ name?: TermName;
31
+ }
32
+ export declare const namedTerms: NamedTerms;
33
+ export declare const namedTermItems: NamedTermItem[];
34
+ export declare const allTermItems: TermItem[];
35
+ export {};
package/lib/terms.js ADDED
@@ -0,0 +1,26 @@
1
+ export const unnamedTermItems = [];
2
+ const terms = {
3
+ company: {
4
+ en: 'Alauda',
5
+ zh: '灵雀云',
6
+ description: '公司品牌',
7
+ },
8
+ product: {
9
+ en: 'Alauda Container Platform',
10
+ zh: '灵雀云容器平台',
11
+ description: '产品品牌',
12
+ },
13
+ productShort: {
14
+ en: 'ACP',
15
+ description: '产品品牌简称',
16
+ },
17
+ };
18
+ export const namedTerms = terms;
19
+ export const namedTermItems = Object.keys(terms).map((name_) => {
20
+ const name = name_;
21
+ return {
22
+ name,
23
+ ...terms[name],
24
+ };
25
+ });
26
+ export const allTermItems = [...namedTermItems, ...unnamedTermItems];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.13.3",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -45,8 +45,8 @@
45
45
  "@inquirer/prompts": "^7.3.2",
46
46
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
47
47
  "@playwright/browser-chromium": "^1.50.1",
48
- "@rspress/core": "1.42.0",
49
- "@shikijs/transformers": "^3.0.0",
48
+ "@rspress/core": "1.42.1",
49
+ "@shikijs/transformers": "^3.1.0",
50
50
  "chokidar": "^4.0.3",
51
51
  "cli-progress": "^3.12.0",
52
52
  "clsx": "^2.1.1",
@@ -68,34 +68,34 @@
68
68
  "remark-directive": "^2.0.1",
69
69
  "remark-frontmatter": "^4.0.1",
70
70
  "remark-gfm": "^3.0.1",
71
- "shiki": "^3.0.0",
71
+ "shiki": "^3.1.0",
72
72
  "simple-git": "^3.27.0",
73
73
  "swagger2openapi": "^7.0.8",
74
74
  "tinyglobby": "^0.2.12",
75
- "type-fest": "^4.35.0",
75
+ "type-fest": "^4.36.0",
76
76
  "yaml": "^2.7.0",
77
77
  "yoctocolors": "^2.1.1"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@eslint/js": "^9.21.0",
81
81
  "@swc-node/register": "^1.10.9",
82
- "@swc/core": "1.10.18",
83
- "@types/cli-progress": "^3",
82
+ "@swc/core": "1.11.5",
83
+ "@types/cli-progress": "^3.11.6",
84
84
  "@types/ejs": "^3.1.5",
85
- "@types/fs-extra": "^11",
86
- "@types/node": "^18.19.76",
85
+ "@types/fs-extra": "^11.0.4",
86
+ "@types/node": "^18.19.78",
87
87
  "@types/picomatch": "^3.0.2",
88
88
  "@types/react": "^18.3.18",
89
89
  "@types/react-dom": "^18.3.5",
90
90
  "@types/swagger2openapi": "^7.0.4",
91
- "@unts/patch-package": "^8.0.0",
91
+ "@unts/patch-package": "^8.1.1",
92
92
  "eslint": "^9.21.0",
93
93
  "lint-staged": "^15.4.3",
94
94
  "npm-run-all2": "^7.0.2",
95
- "prettier": "^3.5.2",
95
+ "prettier": "^3.5.3",
96
96
  "prettier-plugin-pkg": "^0.18.1",
97
97
  "simple-git-hooks": "^2.11.1",
98
- "typescript": "^5.7.3",
98
+ "typescript": "^5.8.2",
99
99
  "typescript-eslint": "^8.25.0"
100
100
  },
101
101
  "publishConfig": {