@alauda/doom 0.19.4 → 0.19.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/global.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="@total-typescript/ts-reset" />
1
2
  /// <reference types="@alauda/doom/types" />
2
3
 
3
4
  type MDXProvidedComponents = typeof import('@alauda/doom/runtime')
@@ -1,7 +1,9 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import { glob } from 'tinyglobby';
3
- import { FALSY_VALUES, isDoc } from '../shared/index.js';
3
+ import { FALSY_VALUES } from '../shared/index.js';
4
4
  export const parseBoolean = (value) => !!value && !FALSY_VALUES.has(value);
5
+ const DOC_PATTERN = /\.mdx?$/;
6
+ const isDoc = (filename) => DOC_PATTERN.test(filename);
5
7
  export const getMatchedDocFilePaths = (matched) => Promise.all(matched.map(async (it) => {
6
8
  const stat = await fs.stat(it);
7
9
  if (stat.isDirectory()) {
package/lib/cli/index.js CHANGED
@@ -28,7 +28,7 @@ program
28
28
  showGlobalOptions: true,
29
29
  })
30
30
  .option('-c, --config <config>', 'Specify the path to the config file')
31
- .option('-v <version>', 'Specify the version of the documentation')
31
+ .option('-v <version>', `Specify the version of the documentation, can also be 'unversioned' or 'unversioned-x.y'`)
32
32
  .option('-b, --base <base>', 'Override the base of the documentation')
33
33
  .option('-p, --prefix <prefix>', 'Specify the prefix of the documentation base')
34
34
  .option('-f, --force [boolean]', `Force to
@@ -37,7 +37,7 @@ program
37
37
  .option('-i, --ignore [boolean]', 'Ignore internal routes', parseBoolean, false)
38
38
  .option('-d, --download [boolean]', 'Display download pdf link on nav bar', parseBoolean, false)
39
39
  .option('-e, --export [boolean]', 'Run or build in exporting PDF mode, `apis/**` and `*/apis/**` routes will be ignored automatically', parseBoolean, false)
40
- .option('--no-open [boolean]', 'Do not open the browser after starting the server')
40
+ .option('-n, --no-open [boolean]', 'Do not open the browser after starting the server')
41
41
  .command('dev', { isDefault: true })
42
42
  .description('Start the development server')
43
43
  .argument('[root]', 'Root directory of the documentation')
@@ -7,8 +7,8 @@ import { logger } from '@rspress/shared/logger';
7
7
  import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
8
8
  import rehypeRaw from 'rehype-raw';
9
9
  import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, replacePlugin, shikiPlugin, } from '../plugins/index.js';
10
- import {} from '../shared/index.js';
11
- import { pkgResolve, resolveStaticConfig } from '../utils/index.js';
10
+ import { isExplicitlyUnversioned, UNVERSIONED, } from '../shared/index.js';
11
+ import { pathExists, pkgResolve, resolveStaticConfig } from '../utils/index.js';
12
12
  import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
13
13
  const DEFAULT_LOGO = '/logo.svg';
14
14
  const zhLocaleConfig = {
@@ -27,12 +27,12 @@ const ruLocaleConfig = {
27
27
  prevPageText: 'Предыдущая страница',
28
28
  nextPageText: 'Следующая страница',
29
29
  };
30
- const getCommonConfig = ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, }) => {
30
+ const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, }) => {
31
31
  const fallbackToZh = 'lang' in config && !config.lang;
32
32
  root = resolveDocRoot(CWD, root, config.root);
33
33
  const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
34
34
  const userBase = (base = addLeadingSlash(addTrailingSlash(base || config.base || '/')));
35
- if (version && version !== 'unversioned') {
35
+ if (version && !isExplicitlyUnversioned(version)) {
36
36
  base = userBase + `${version}/`;
37
37
  }
38
38
  return {
@@ -70,8 +70,12 @@ const getCommonConfig = ({ config, root, configFilePath, base, version, download
70
70
  locales: [
71
71
  { lang: 'en', label: 'English' },
72
72
  { lang: 'zh', label: '简体中文', ...zhLocaleConfig },
73
- { lang: 'ru', label: 'Русский', ...ruLocaleConfig },
74
- ],
73
+ (await pathExists(path.resolve(root, 'ru'), 'directory')) && {
74
+ lang: 'ru',
75
+ label: 'Русский',
76
+ ...ruLocaleConfig,
77
+ },
78
+ ].filter(Boolean),
75
79
  }),
76
80
  },
77
81
  plugins: [
@@ -193,7 +197,7 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
193
197
  }
194
198
  }
195
199
  version ||= '';
196
- const commonConfig = getCommonConfig({
200
+ const commonConfig = await getCommonConfig({
197
201
  config,
198
202
  configFilePath,
199
203
  root,
@@ -244,7 +248,7 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
244
248
  mergedConfig.outDir = addTrailingSlash(mergedConfig.outDir) + version;
245
249
  }
246
250
  else {
247
- mergedConfig.outDir = `dist${version === 'unversioned' ? `${base}unversioned` : base}`;
251
+ mergedConfig.outDir = `dist${isExplicitlyUnversioned(version) ? `${base}${UNVERSIONED}` : base}`;
248
252
  }
249
253
  if (mergedConfig.builderConfig?.server?.open === true) {
250
254
  mergedConfig.builderConfig.server.open = mergedConfig.base;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Tag } from '@rspress/core/theme';
3
3
  import { isExternalUrl, withoutBase, } from '@rspress/shared';
4
- import { useState } from 'react';
4
+ import { useCallback, useState } from 'react';
5
5
  import { SvgDown } from './Down.js';
6
6
  import { NavMenuSingleItem, } from './NavMenuSingleItem.js';
7
7
  import { SvgWrapper } from './SvgWrapper.js';
@@ -18,6 +18,12 @@ function NormalGroupItem({ item }) {
18
18
  export function NavMenuGroup(item) {
19
19
  const { activeValue, items: groupItems, base = '', pathname = '' } = item;
20
20
  const [isOpen, setIsOpen] = useState(false);
21
+ const onOpen = useCallback(() => {
22
+ setIsOpen(true);
23
+ }, []);
24
+ const onClose = useCallback(() => {
25
+ setIsOpen(false);
26
+ }, []);
21
27
  const renderLinkItem = (item) => {
22
28
  const isLinkActive = new RegExp(item.activeMatch || item.link).test(withoutBase(pathname, base));
23
29
  if (activeValue === item.text || (!activeValue && isLinkActive)) {
@@ -28,13 +34,10 @@ export function NavMenuGroup(item) {
28
34
  const renderGroup = (item) => {
29
35
  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
36
  };
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: item.link ? (_jsx(NavMenuSingleItem, { ...item, rightIcon: _jsx(SvgWrapper, { icon: SvgDown }) })) : (_jsxs(_Fragment, { children: [_jsxs("span", { className: "text-sm font-medium flex", style: {
36
- marginRight: '2px',
37
- }, 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: {
37
+ const hasMultiItems = groupItems.length > 1;
38
+ const Content = hasMultiItems || item.link ? 'button' : 'span';
39
+ const content = (_jsx(Content, { onMouseEnter: hasMultiItems ? onOpen : undefined, className: `${Content === 'button' ? 'rspress-nav-menu-group-button ' : ''}flex-center items-center font-medium text-sm text-text-1${hasMultiItems ? ' hover:text-text-2 transition-colors duration-200' : ''}`, children: item.link ? (_jsx(NavMenuSingleItem, { ...item, rightIcon: _jsx(SvgWrapper, { icon: SvgDown }) })) : (_jsxs(_Fragment, { children: [_jsxs("span", { className: "text-sm font-medium flex", style: hasMultiItems ? { marginRight: '2px' } : undefined, children: [_jsx(Tag, { tag: item.tag }), item.text] }), hasMultiItems && _jsx(SvgWrapper, { icon: SvgDown })] })) }));
40
+ return hasMultiItems ? (_jsxs("div", { className: "relative flex-center h-14", onMouseLeave: onClose, children: [content, _jsx("div", { className: "rspress-nav-menu-group-content absolute mx-0.8 transition-opacity duration-300", style: {
38
41
  opacity: isOpen ? 1 : 0,
39
42
  visibility: isOpen ? 'visible' : 'hidden',
40
43
  right: 0,
@@ -45,5 +48,5 @@ export function NavMenuGroup(item) {
45
48
  border: '1px solid var(--rp-c-divider-light)',
46
49
  borderRadius: 'var(--rp-radius-large)',
47
50
  background: 'var(--rp-c-bg)',
48
- }, children: groupItems.map((item) => (_jsx("div", { children: 'items' in item ? renderGroup(item) : renderLinkItem(item) }, item.text))) }) })] }));
51
+ }, children: groupItems.map((item) => (_jsx("div", { children: 'items' in item ? renderGroup(item) : renderLinkItem(item) }, item.text))) }) })] })) : (content);
49
52
  }
@@ -1,14 +1,14 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { isProduction, NoSSR, removeTrailingSlash, useLang, usePageData, } from '@rspress/core/runtime';
2
+ import { isProduction, NoSSR, removeTrailingSlash, usePageData, } from '@rspress/core/runtime';
3
3
  import virtual from 'doom-@global-virtual';
4
4
  import { noop } from 'es-toolkit';
5
5
  import { useEffect, useMemo, useState } from 'react';
6
6
  import { createPortal } from 'react-dom';
7
7
  import { parse } from 'yaml';
8
- import { ACP_BASE, getPdfName } from '../../shared/index.js';
8
+ import { ACP_BASE, getPdfName, getUnversionedVersion, isExplicitlyUnversioned, } from '../../shared/index.js';
9
9
  import { NavMenuGroup } from './NavMenuGroup.js';
10
10
  import { NavMenuSingleItem } from './NavMenuSingleItem.js';
11
- import { useTranslation } from '@alauda/doom/runtime';
11
+ import { useLang, useTranslation } from '@alauda/doom/runtime';
12
12
  const getNavMenu = () => {
13
13
  if (typeof document === 'undefined') {
14
14
  return null;
@@ -35,38 +35,45 @@ const VersionsNav_ = () => {
35
35
  return siteData.base + getPdfName(lang, virtual.userBase, siteData.title);
36
36
  }, [lang, siteData.base, siteData.title]);
37
37
  const [versionsBase, version] = useMemo(() => {
38
- if (!virtual.version) {
38
+ const unversionedVersion = getUnversionedVersion(virtual.version);
39
+ if (!unversionedVersion) {
39
40
  return [];
40
41
  }
41
42
  return [
42
- removeTrailingSlash(siteData.base).slice(0, -virtual.version.length - 1),
43
- virtual.version,
43
+ isExplicitlyUnversioned(virtual.version)
44
+ ? undefined
45
+ : removeTrailingSlash(siteData.base).slice(0, -unversionedVersion.length - 1),
46
+ unversionedVersion,
44
47
  ];
45
48
  }, [siteData.base]);
46
49
  const [navMenu, setNavMenu] = useState(getNavMenu);
47
- const [versions, setVersions] = useState();
50
+ const [versions, setVersions] = useState(version ? [version] : []);
48
51
  useEffect(() => {
49
52
  const fetchVersions = async () => {
50
53
  if (versionsBase == null) {
51
- return;
54
+ if (!version) {
55
+ return;
56
+ }
52
57
  }
53
- const res = await fetch(`${isProduction() ? versionsBase : ''}/versions.yaml`);
54
- if (!res.ok) {
55
- return;
58
+ else {
59
+ const res = await fetch(`${isProduction() ? versionsBase : ''}/versions.yaml`);
60
+ if (!res.ok) {
61
+ return;
62
+ }
63
+ const text = await res.text();
64
+ const versions = parse(text);
65
+ if (version && !versions.includes(version)) {
66
+ versions.unshift(version);
67
+ }
68
+ setVersions(versions);
56
69
  }
57
- const text = await res.text();
58
- const versions = parse(text);
59
- if (version && !versions.includes(version)) {
60
- versions.unshift(version);
61
- }
62
- setVersions(versions);
63
70
  setNavMenu(getNavMenu);
64
71
  };
65
72
  void fetchVersions().catch(noop);
66
73
  }, []);
67
74
  // hack way to detect nav menu recreation on theme change
68
75
  useEffect(() => {
69
- if (!navMenu) {
76
+ if (!navMenu?.parentNode) {
70
77
  return;
71
78
  }
72
79
  const observer = new MutationObserver((mutations) => {
@@ -74,18 +81,18 @@ const VersionsNav_ = () => {
74
81
  setNavMenu(getNavMenu);
75
82
  }
76
83
  });
77
- observer.observe(navMenu, { childList: true });
84
+ observer.observe(navMenu.parentNode, { childList: true });
78
85
  return () => {
79
86
  observer.disconnect();
80
87
  };
81
88
  }, [navMenu]);
89
+ console.log('versionsBase', versionsBase);
82
90
  const navItems = useMemo(() => {
83
- const versionItems = (versions || []).map((v) => ({
84
- text: v,
85
- link: `${versionsBase}/${v}/`,
86
- activeMatch: v,
87
- }));
88
- if (ALLOW_LEGACY_DOMAINS.includes(location.hostname) &&
91
+ const versionItems = versions.map((v) => versionsBase == null
92
+ ? { text: v, items: [] }
93
+ : { text: v, link: `${versionsBase}/${v}/`, activeMatch: v });
94
+ if (versionsBase != null &&
95
+ ALLOW_LEGACY_DOMAINS.includes(location.hostname) &&
89
96
  virtual.userBase === ACP_BASE) {
90
97
  versionItems.push(...LEGACY_NAV_ITEMS);
91
98
  }
@@ -28,7 +28,7 @@ export const globalPlugin = ({ version, download, }) => {
28
28
  'doom-@global-virtual': `export default ${JSON.stringify({
29
29
  userBase: config.userBase,
30
30
  prefix: config.prefix,
31
- version: version === 'unversioned' ? undefined : version,
31
+ version,
32
32
  download,
33
33
  sites: config.sites?.map((site) => ({
34
34
  ...site,
@@ -6,6 +6,7 @@ import { clsx } from 'clsx';
6
6
  import virtual from 'doom-@global-virtual';
7
7
  import { useMemo } from 'react';
8
8
  import classes from '../../../styles/link.module.scss';
9
+ import { isUnversioned } from '../../shared/helpers.js';
9
10
  import { useIsPrint } from '../hooks/index.js';
10
11
  import { Directive } from './Directive.js';
11
12
  const ExternalSiteLink_ = ({ name, href = '', className, ...props }) => {
@@ -28,9 +29,9 @@ const ExternalSiteLink_ = ({ name, href = '', className, ...props }) => {
28
29
  url = removeLeadingSlash(normalizeHref(url));
29
30
  return (_jsx("a", { href: (isPrint ? 'https://docs.alauda.io' : '') +
30
31
  (virtual.prefix || '') +
31
- (virtual.version
32
- ? addTrailingSlash(site.base + site.version)
33
- : site.base) +
32
+ (isUnversioned(virtual.version)
33
+ ? site.base
34
+ : addTrailingSlash(site.base + site.version)) +
34
35
  (lang ? addTrailingSlash(lang) : '') +
35
36
  (hash ? `${url}#${hash}` : url), target: "_blank", rel: "noopener noreferrer", className: clsx(classes.link, 'cursor-pointer', className), ...props }));
36
37
  };
@@ -1,4 +1,4 @@
1
- import type { Language } from '../../shared/index.js';
1
+ import { type Language } from '../../shared/index.js';
2
2
  import { type NamedTerms, type TermName } from '../../terms.js';
3
3
  export type SiteOverridesTerms = Record<TermName, string>;
4
4
  export interface SiteOverridesItem {
@@ -3,6 +3,7 @@ import virtual from 'doom-@global-virtual';
3
3
  import { merge } from 'es-toolkit/compat';
4
4
  import { useEffect, useMemo, useState } from 'react';
5
5
  import { parse } from 'yaml';
6
+ import { isUnversioned } from '../../shared/index.js';
6
7
  import { namedTerms } from '../../terms.js';
7
8
  import { useLang } from './useTranslation.js';
8
9
  const normalizeOverrides = (origin) => Object.keys(origin).reduce((acc, key_) => {
@@ -23,7 +24,7 @@ const fetchSiteOverrides = async (base, version, acpSite) => {
23
24
  return promise;
24
25
  }
25
26
  const acpSiteOverridesUrl = acpSite && isProduction()
26
- ? `${(virtual.prefix || '') + acpSite.base}${version ? acpSite.version + '/' : ''}overrides.yaml`
27
+ ? `${(virtual.prefix || '') + acpSite.base}${isUnversioned(version) ? '' : acpSite.version + '/'}overrides.yaml`
27
28
  : null;
28
29
  const siteOverridesUrl = `${isProduction() ? base : '/'}overrides.yaml`;
29
30
  const urls = [acpSiteOverridesUrl];
@@ -9,3 +9,5 @@ export declare const Language: {
9
9
  };
10
10
  export type Language = keyof typeof Language;
11
11
  export declare const SUPPORTED_LANGUAGES: Language[];
12
+ export declare const UNVERSIONED = "unversioned";
13
+ export declare const UNVERSIONED_PREFIX = "unversioned-";
@@ -14,3 +14,5 @@ export const Language = {
14
14
  ru: '俄文',
15
15
  };
16
16
  export const SUPPORTED_LANGUAGES = Object.keys(Language);
17
+ export const UNVERSIONED = 'unversioned';
18
+ export const UNVERSIONED_PREFIX = `${UNVERSIONED}-`;
@@ -1,4 +1,6 @@
1
+ import type { UnversionedVersion } from './types.js';
1
2
  export declare const removeBothEndsSlashes: (str?: string) => string;
2
3
  export declare const getPdfName: (lang: string, userBase?: string, title?: string) => string;
3
- export declare const DOC_PATTERN: RegExp;
4
- export declare const isDoc: (filename: string) => boolean;
4
+ export declare const isExplicitlyUnversioned: (version?: string) => version is UnversionedVersion;
5
+ export declare const isUnversioned: (version?: string) => version is undefined | "" | UnversionedVersion;
6
+ export declare const getUnversionedVersion: (version?: string) => string | undefined;
@@ -1,4 +1,13 @@
1
+ import { UNVERSIONED, UNVERSIONED_PREFIX } from './constants.js';
1
2
  export const removeBothEndsSlashes = (str) => str?.replace(/^\/|\/$/g, '') || '';
2
3
  export const getPdfName = (lang, userBase, title) => `${removeBothEndsSlashes(userBase) || title || 'exported'}-${lang}.pdf`;
3
- export const DOC_PATTERN = /\.mdx?$/;
4
- export const isDoc = (filename) => DOC_PATTERN.test(filename);
4
+ export const isExplicitlyUnversioned = (version) => version === UNVERSIONED || !!version?.startsWith(UNVERSIONED_PREFIX);
5
+ export const isUnversioned = (version) => !version || isExplicitlyUnversioned(version);
6
+ export const getUnversionedVersion = (version) => {
7
+ if (!version || version === UNVERSIONED) {
8
+ return;
9
+ }
10
+ return version.startsWith(UNVERSIONED_PREFIX)
11
+ ? version.slice(UNVERSIONED_PREFIX.length)
12
+ : version;
13
+ };
@@ -1,3 +1,4 @@
1
+ import type { UNVERSIONED } from './constants.js';
1
2
  export interface DoomSite {
2
3
  name: string;
3
4
  base: string;
@@ -19,3 +20,4 @@ export interface K8sTypeMeta {
19
20
  export interface K8sTypeList<T extends K8sTypeMeta> extends K8sTypeMeta {
20
21
  items: T[];
21
22
  }
23
+ export type UnversionedVersion = typeof UNVERSIONED | `${typeof UNVERSIONED}-${string}`;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.19.4",
3
+ "version": "0.19.6",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "https://gitlab-ce.alauda.cn/idp/Doom.git",
7
- "packageManager": "yarn@4.9.0",
7
+ "packageManager": "yarn@4.9.1",
8
8
  "engines": {
9
9
  "node": ">=18.17.0 <20 || >=20.1.0"
10
10
  },
@@ -52,7 +52,7 @@
52
52
  "clsx": "^2.1.1",
53
53
  "commander": "^13.1.0",
54
54
  "ejs": "^3.1.10",
55
- "es-toolkit": "^1.34.1",
55
+ "es-toolkit": "^1.35.0",
56
56
  "html-tag-names": "^2.1.0",
57
57
  "mermaid": "^11.6.0",
58
58
  "openai": "^5.0.0-beta.0",
@@ -71,7 +71,7 @@
71
71
  "simple-git": "^3.27.0",
72
72
  "swagger2openapi": "^7.0.8",
73
73
  "tinyglobby": "^0.2.12",
74
- "type-fest": "^4.39.1",
74
+ "type-fest": "^4.40.0",
75
75
  "x-fetch": "^0.2.6",
76
76
  "yaml": "^2.7.1",
77
77
  "yoctocolors": "^2.1.1"
@@ -80,6 +80,7 @@
80
80
  "@eslint/js": "^9.24.0",
81
81
  "@swc-node/register": "^1.10.10",
82
82
  "@swc/core": "1.11.21",
83
+ "@total-typescript/ts-reset": "^0.6.1",
83
84
  "@types/cli-progress": "^3.11.6",
84
85
  "@types/ejs": "^3.1.5",
85
86
  "@types/node": "^18.19.86",
@@ -90,14 +91,14 @@
90
91
  "@unts/patch-package": "^8.1.1",
91
92
  "eslint": "^9.24.0",
92
93
  "eslint-import-resolver-typescript": "^4.3.2",
93
- "eslint-plugin-import-x": "^4.10.3",
94
+ "eslint-plugin-import-x": "^4.10.5",
94
95
  "nano-staged": "^0.8.0",
95
96
  "npm-run-all2": "^7.0.2",
96
97
  "prettier": "^3.5.3",
97
98
  "prettier-plugin-pkg": "^0.19.0",
98
99
  "simple-git-hooks": "^2.12.1",
99
100
  "typescript": "^5.8.3",
100
- "typescript-eslint": "^8.29.1",
101
+ "typescript-eslint": "^8.30.1",
101
102
  "yarn-berry-deduplicate": "^6.1.1"
102
103
  },
103
104
  "publishConfig": {