@alauda/doom 1.8.1 → 1.9.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 (58) hide show
  1. package/lib/cli/export.js +2 -2
  2. package/lib/cli/index.js +8 -6
  3. package/lib/cli/lint.d.ts +4 -0
  4. package/lib/cli/lint.js +8 -4
  5. package/lib/cli/load-config.d.ts +1 -1
  6. package/lib/cli/load-config.js +6 -4
  7. package/lib/cli/translate.js +1 -1
  8. package/lib/eslint.d.ts +1 -1
  9. package/lib/eslint.js +23 -7
  10. package/lib/global/VersionsNav/NavMenuGroup.js +2 -1
  11. package/lib/global/VersionsNav/NavMenuSingleItem.js +2 -1
  12. package/lib/global/VersionsNav/index.js +6 -5
  13. package/lib/plugins/auto-sidebar/utils.js +1 -1
  14. package/lib/plugins/replace/parse-toc.js +1 -1
  15. package/lib/plugins/replace/utils.d.ts +0 -4
  16. package/lib/plugins/replace/utils.js +0 -12
  17. package/lib/remark-lint/constants.d.ts +1 -0
  18. package/lib/remark-lint/constants.js +1 -0
  19. package/lib/remark-lint/index.d.ts +17 -0
  20. package/lib/remark-lint/index.js +21 -0
  21. package/lib/remark-lint/list-item-punctuation.d.ts +2 -0
  22. package/lib/remark-lint/list-item-punctuation.js +72 -0
  23. package/lib/remark-lint/list-item-size.d.ts +2 -0
  24. package/lib/remark-lint/list-item-size.js +15 -0
  25. package/lib/remark-lint/list-table-introduction.d.ts +2 -0
  26. package/lib/remark-lint/list-table-introduction.js +17 -0
  27. package/lib/remark-lint/maximum-link-content-length.d.ts +2 -0
  28. package/lib/remark-lint/maximum-link-content-length.js +29 -0
  29. package/lib/remark-lint/no-deep-heading.d.ts +2 -0
  30. package/lib/remark-lint/no-deep-heading.js +13 -0
  31. package/lib/remark-lint/no-deep-list.d.ts +2 -0
  32. package/lib/remark-lint/no-deep-list.js +14 -0
  33. package/lib/remark-lint/no-empty-table-cell.d.ts +2 -0
  34. package/lib/remark-lint/no-empty-table-cell.js +12 -0
  35. package/lib/remark-lint/no-heading-punctuation.d.ts +2 -0
  36. package/lib/remark-lint/no-heading-punctuation.js +28 -0
  37. package/lib/remark-lint/no-heading-special-characters.d.ts +2 -0
  38. package/lib/remark-lint/no-heading-special-characters.js +26 -0
  39. package/lib/remark-lint/no-heading-sup-sub.d.ts +2 -0
  40. package/lib/remark-lint/no-heading-sup-sub.js +16 -0
  41. package/lib/remark-lint/no-paragraph-indent.d.ts +2 -0
  42. package/lib/remark-lint/no-paragraph-indent.js +27 -0
  43. package/lib/remark-lint/table-size.d.ts +2 -0
  44. package/lib/remark-lint/table-size.js +14 -0
  45. package/lib/remark-lint/unit-case.d.ts +2 -0
  46. package/lib/remark-lint/unit-case.js +29 -0
  47. package/lib/remarkrc.d.ts +4 -0
  48. package/lib/remarkrc.js +58 -0
  49. package/lib/runtime/components/Overview.js +10 -12
  50. package/lib/runtime/components/_utils.d.ts +5 -1
  51. package/lib/runtime/components/_utils.js +5 -1
  52. package/lib/runtime/hooks/useSiteOverrides.js +5 -5
  53. package/lib/shared/helpers.d.ts +8 -1
  54. package/lib/shared/helpers.js +16 -1
  55. package/lib/shared/types.d.ts +1 -1
  56. package/package.json +37 -20
  57. package/pyodide/package.json +1 -1
  58. package/styles/global.scss +5 -5
package/lib/cli/export.js CHANGED
@@ -38,7 +38,7 @@ export const exportCommand = new Command('export')
38
38
  .action(async function (root) {
39
39
  setNodeEnv('production');
40
40
  const { port, host, ...globalOptions } = this.optsWithGlobals();
41
- let { config } = await loadConfig(root, {
41
+ let { config, configFilePath } = await loadConfig(root, {
42
42
  ...globalOptions,
43
43
  export: true,
44
44
  });
@@ -55,7 +55,7 @@ export const exportCommand = new Command('export')
55
55
  // make sure it won't be overridden by `serve`
56
56
  const themeConfig = { ...config.themeConfig };
57
57
  logger.start('Serving...');
58
- await serve({ config, host, port });
58
+ await serve({ config, configFilePath, host, port });
59
59
  const tempDir = path.resolve(outDir, '.doom');
60
60
  const commonOptions = {
61
61
  tempDir,
package/lib/cli/index.js CHANGED
@@ -59,11 +59,12 @@ program
59
59
  let cliWatcher;
60
60
  const { port, host, ...globalOptions } = this.optsWithGlobals();
61
61
  const startDevServer = async () => {
62
- const { config, filepath } = await loadConfig(root, globalOptions);
62
+ const { config, configFilePath } = await loadConfig(root, globalOptions);
63
63
  const docDirectory = config.root;
64
64
  try {
65
65
  devServer = await dev({
66
66
  config,
67
+ configFilePath,
67
68
  appDirectory: CWD,
68
69
  docDirectory,
69
70
  extraBuilderConfig: {
@@ -75,8 +76,8 @@ program
75
76
  logger.error(err);
76
77
  devServer = undefined;
77
78
  }
78
- cliWatcher = watch(filepath
79
- ? [filepath, config.i18nSourcePath, docDirectory, SITES_FILE]
79
+ cliWatcher = watch(configFilePath
80
+ ? [configFilePath, config.i18nSourcePath, docDirectory, SITES_FILE]
80
81
  : [...CONFIG_FILES, docDirectory], {
81
82
  ignoreInitial: true,
82
83
  ignored: ['**/node_modules/**', '**/.git/**', '**/.DS_Store/**'],
@@ -121,10 +122,11 @@ program
121
122
  .argument('[root]', 'Root directory of the documentation')
122
123
  .action(async function (root) {
123
124
  setNodeEnv('production');
124
- const { config } = await loadConfig(root, this.optsWithGlobals());
125
+ const { config, configFilePath } = await loadConfig(root, this.optsWithGlobals());
125
126
  const docDirectory = config.root;
126
127
  const runBuild = () => build({
127
128
  config,
129
+ configFilePath,
128
130
  docDirectory,
129
131
  });
130
132
  await runBuild();
@@ -143,8 +145,8 @@ program
143
145
  .action(async function (root) {
144
146
  setNodeEnv('production');
145
147
  const { port, host, ...globalOptions } = this.optsWithGlobals();
146
- const { config } = await loadConfig(root, globalOptions);
147
- await serve({ config, host, port });
148
+ const { config, configFilePath } = await loadConfig(root, globalOptions);
149
+ await serve({ config, configFilePath, host, port });
148
150
  });
149
151
  program.addCommand(newCommand);
150
152
  program.addCommand(translateCommand);
package/lib/cli/lint.d.ts CHANGED
@@ -1,2 +1,6 @@
1
1
  import { Command } from 'commander';
2
+ export interface LintCommandOptions {
3
+ cspell?: boolean;
4
+ glob: string | string[];
5
+ }
2
6
  export declare const lintCommand: Command;
package/lib/cli/lint.js CHANGED
@@ -1,23 +1,27 @@
1
+ import path from 'node:path';
1
2
  import { logger } from '@rspress/shared/logger';
2
3
  import { Command } from 'commander';
3
4
  import { ESLint } from 'eslint';
5
+ import { cyan } from 'yoctocolors';
4
6
  import doom from '../eslint.js';
5
7
  import { loadConfig } from './load-config.js';
6
8
  export const lintCommand = new Command('lint')
7
9
  .description('Lint the documentation')
8
10
  .argument('[root]', 'Root directory of the documentation')
11
+ .option('-g, --glob <path...>', 'Glob patterns of source dirs/files to lint', '**/*.{js,jsx,ts,tsx,md,mdx}')
12
+ .option('--no-cspell', 'Disable cspell linting')
9
13
  .action(async function (root) {
10
- const globalOptions = this.optsWithGlobals();
14
+ const { cspell, glob, ...globalOptions } = this.optsWithGlobals();
11
15
  const { config } = await loadConfig(root, globalOptions);
12
16
  const docsDir = config.root;
13
17
  const eslint = new ESLint({
14
18
  cwd: docsDir,
15
19
  overrideConfigFile: true,
16
20
  // @ts-expect-error -- stronger types
17
- overrideConfig: await doom(config.lint?.cspellOptions),
21
+ overrideConfig: await doom(cspell ? config.lint?.cspellOptions : null),
18
22
  });
19
- logger.start('Linting...');
20
- const results = await eslint.lintFiles('**/*.{js,jsx,ts,tsx,md,mdx}');
23
+ logger.start(`Linting \`${cyan(path.relative(process.cwd(), docsDir))}\`...`);
24
+ const results = await eslint.lintFiles(glob);
21
25
  const { error, warning } = results.reduce((count, result) => ({
22
26
  error: count.error + result.errorCount,
23
27
  warning: count.warning + result.warningCount,
@@ -2,6 +2,6 @@ import { type UserConfig } from '@rspress/core';
2
2
  import type { GlobalCliOptions } from '../types.js';
3
3
  export declare function loadConfig(root?: string | URL, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, editRepo, algolia, siteUrl, }?: GlobalCliOptions): Promise<{
4
4
  config: UserConfig;
5
- filepath?: string;
5
+ configFilePath: string;
6
6
  }>;
7
7
  export declare function resolveDocRoot(cliRoot?: string, configRoot?: string): string;
@@ -216,6 +216,11 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
216
216
  server: {
217
217
  open,
218
218
  },
219
+ performance: {
220
+ buildCache: {
221
+ cacheDigest: [root, configFilePath, base, version],
222
+ },
223
+ },
219
224
  tools: {
220
225
  rspack(rspackConfig, { mergeConfig, rspack }) {
221
226
  return mergeConfig(rspackConfig, {
@@ -361,12 +366,9 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
361
366
  outDir ||= mergedConfig.outDir;
362
367
  mergedConfig.outDir = `dist${(outDir ? addLeadingSlash(addTrailingSlash(outDir)) : base) +
363
368
  (isExplicitlyUnversioned(version) ? UNVERSIONED : outDir ? version : '')}`;
364
- if (mergedConfig.builderConfig?.server?.open === true) {
365
- mergedConfig.builderConfig.server.open = mergedConfig.base;
366
- }
367
369
  return {
368
370
  config: mergedConfig,
369
- filepath: configFilePath,
371
+ configFilePath: configFilePath || '',
370
372
  };
371
373
  }
372
374
  export function resolveDocRoot(cliRoot, configRoot) {
@@ -265,7 +265,7 @@ export const translateCommand = new Command('translate')
265
265
  .argument('[root]', 'Root directory of the documentation')
266
266
  .option('-s, --source <language>', `Document source language, one of ${supportedLanguages}`, 'en')
267
267
  .option('-t, --target <language>', `Document target language, one of ${supportedLanguages}`, 'zh')
268
- .requiredOption('-g, --glob <path...>', 'Glob patterns for source dirs/files')
268
+ .requiredOption('-g, --glob <path...>', 'Glob patterns of source dirs/files to translate')
269
269
  .option('-C, --copy [boolean]', 'Wether to copy relative assets to the target directory instead of following links', parseBoolean, false)
270
270
  .action(async function (root) {
271
271
  const { source, target, glob: globs, copy, force, ...globalOptions } = this.optsWithGlobals();
package/lib/eslint.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Options } from '@cspell/eslint-plugin';
2
2
  import tseslint from 'typescript-eslint';
3
- declare function doom(cspellOptions?: Options): Promise<tseslint.ConfigArray>;
3
+ declare function doom(cspellOptions?: Options | null): Promise<tseslint.ConfigArray>;
4
4
  declare function doom(root: string | URL): Promise<tseslint.ConfigArray>;
5
5
  export default doom;
package/lib/eslint.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { createRequire } from 'node:module';
2
+ import { fileURLToPath } from 'node:url';
1
3
  import cspellRecommended from '@cspell/eslint-plugin/recommended';
2
4
  import js from '@eslint/js';
3
5
  import react from '@eslint-react/eslint-plugin';
@@ -6,6 +8,14 @@ import * as mdx from 'eslint-plugin-mdx';
6
8
  import globals from 'globals';
7
9
  import tseslint from 'typescript-eslint';
8
10
  import { loadConfig } from './cli/load-config.js';
11
+ const cjsRequire = createRequire(import.meta.url);
12
+ let remarkConfigPath;
13
+ try {
14
+ remarkConfigPath = fileURLToPath(import.meta.resolve('./remarkrc.js'));
15
+ }
16
+ catch {
17
+ remarkConfigPath = cjsRequire.resolve('./remarkrc.js');
18
+ }
9
19
  async function doom(cspellOptionsOrRoot) {
10
20
  let cspellOptions;
11
21
  if (typeof cspellOptionsOrRoot === 'string' ||
@@ -16,6 +26,7 @@ async function doom(cspellOptionsOrRoot) {
16
26
  else {
17
27
  cspellOptions = cspellOptionsOrRoot;
18
28
  }
29
+ const cspellEnabled = cspellOptions !== null;
19
30
  return tseslint.config([
20
31
  {
21
32
  ignores: ['**/.yarn', '**/dist', '**/lib', '**/node_modules'],
@@ -32,16 +43,21 @@ async function doom(cspellOptionsOrRoot) {
32
43
  },
33
44
  {
34
45
  files: ['**/en/**/*.{js,jsx,md,mdx,ts,tsx}'],
35
- extends: [cspellRecommended],
46
+ extends: cspellEnabled ? [cspellRecommended] : [],
36
47
  languageOptions: {
37
48
  globals: globals.browser,
49
+ parserOptions: {
50
+ remarkConfigPath,
51
+ },
38
52
  },
39
- rules: {
40
- '@cspell/spellchecker': [
41
- 'error',
42
- merge({ autoFix: true }, cspellOptions),
43
- ],
44
- },
53
+ rules: cspellEnabled
54
+ ? {
55
+ '@cspell/spellchecker': [
56
+ 'error',
57
+ merge({ autoFix: true }, cspellOptions),
58
+ ],
59
+ }
60
+ : {},
45
61
  },
46
62
  {
47
63
  files: ['**/*.mdx'],
@@ -1,7 +1,8 @@
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
- import { isExternalUrl, matchNavbar, } from '@rspress/shared';
3
+ import { isExternalUrl, } from '@rspress/shared';
4
4
  import { useRef, useState } from 'react';
5
+ import { matchNavbar } from '../../shared/index.js';
5
6
  import { Down } from './Down.js';
6
7
  import { NavMenuSingleItem, } from './NavMenuSingleItem.js';
7
8
  import { SvgWrapper } from './SvgWrapper.js';
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Tag } from '@rspress/core/theme';
3
- import { isExternalUrl, withoutBase, } from '@rspress/shared';
3
+ import { isExternalUrl } from '@rspress/shared';
4
4
  import { useMemo } from 'react';
5
5
  import styles from '../../../styles/versions-nav.module.scss';
6
+ import { withoutBase } from '../../shared/index.js';
6
7
  export function NavMenuSingleItem({ activeMatch, base, compact, download, link, pathname, rightIcon, text, tag, }) {
7
8
  const isActive = useMemo(() => !!base &&
8
9
  !!pathname &&
@@ -1,10 +1,11 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { isProduction, NoSSR, removeTrailingSlash, usePageData, withBase, } from '@rspress/core/runtime';
2
+ import { isProduction, NoSSR, usePageData, withBase, } from '@rspress/core/runtime';
3
3
  import {} from '@rspress/shared';
4
4
  import virtual from 'doom-@global-virtual';
5
5
  import { noop } from 'es-toolkit';
6
6
  import { useEffect, useMemo, useState } from 'react';
7
7
  import { createPortal } from 'react-dom';
8
+ import { base } from 'virtual-runtime-config';
8
9
  import { parse } from 'yaml';
9
10
  import { ACP_BASE, getPdfName, getUnversionedVersion, isExplicitlyUnversioned, } from '../../shared/index.js';
10
11
  import { NavMenuGroup } from './NavMenuGroup.js';
@@ -44,10 +45,10 @@ const VersionsNav_ = () => {
44
45
  return [
45
46
  isExplicitlyUnversioned(virtual.version)
46
47
  ? undefined
47
- : removeTrailingSlash(siteData.base).slice(0, -unversionedVersion.length - 1),
48
+ : base.slice(0, -unversionedVersion.length - 1),
48
49
  unversionedVersion,
49
50
  ];
50
- }, [siteData.base]);
51
+ }, []);
51
52
  const [navMenu, setNavMenu] = useState(getNavMenu);
52
53
  const [versions, setVersions] = useState(version ? [version] : []);
53
54
  useEffect(() => {
@@ -58,7 +59,7 @@ const VersionsNav_ = () => {
58
59
  }
59
60
  }
60
61
  else {
61
- const res = await fetch(`${isProduction() ? versionsBase : ''}/versions.yaml`);
62
+ const res = await fetch(`${isProduction() ? versionsBase : base}/versions.yaml`);
62
63
  if (!res.ok) {
63
64
  return;
64
65
  }
@@ -111,7 +112,7 @@ const VersionsNav_ = () => {
111
112
  !(finalNavMenu = getNavMenu())) {
112
113
  return;
113
114
  }
114
- return createPortal(_jsxs(_Fragment, { children: [downloadLink && (_jsx(NavMenuSingleItem, { text: t('download_pdf'), link: downloadLink, download: true })), !navItems.length || (_jsx(NavMenuGroup, { text: version, base: versionsBase, items: navItems, pathname: siteData.base }))] }), finalNavMenu);
115
+ return createPortal(_jsxs(_Fragment, { children: [downloadLink && (_jsx(NavMenuSingleItem, { text: t('download_pdf'), link: downloadLink, download: true })), !navItems.length || (_jsx(NavMenuGroup, { text: version, base: versionsBase, items: navItems, pathname: base }))] }), finalNavMenu);
115
116
  };
116
117
  export const VersionsNav = () => (_jsx(NoSSR, { children: _jsx(VersionsNav_, {}) }));
117
118
  export default VersionsNav;
@@ -2,8 +2,8 @@ import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import { logger } from '@rspress/shared/logger';
4
4
  import { loadFrontMatter } from '@rspress/shared/node-utils';
5
+ import { extractTextAndId } from '../../shared/index.js';
5
6
  import { pathExists } from '../../utils/index.js';
6
- import { extractTextAndId } from '../replace/utils.js';
7
7
  export async function detectFilePath(rawPath, extensions) {
8
8
  // The params doesn't have extension name, so we need to try to find the file with the extension name.
9
9
  let realPath = rawPath;
@@ -1,6 +1,6 @@
1
1
  import Slugger from 'github-slugger';
2
2
  import { visitChildren } from 'unist-util-visit-children';
3
- import { extractTextAndId } from './utils.js';
3
+ import { extractTextAndId } from '../../shared/index.js';
4
4
  export const parseToc = (tree, allDepths) => {
5
5
  let title = '';
6
6
  const toc = [];
@@ -2,10 +2,6 @@ import type { Root, Yaml } from 'mdast';
2
2
  import { type Options } from 'remark-stringify';
3
3
  import type { NormalizedReferenceSource, ReferenceItem } from './types.js';
4
4
  export declare const RELATIVE_URL_PATTERN: RegExp;
5
- /**
6
- * hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
7
- */
8
- export declare const extractTextAndId: (title: string) => string[];
9
5
  export declare const normalizeReferenceItems: (items?: ReferenceItem[]) => Record<string, NormalizedReferenceSource>;
10
6
  export declare const stringifySettings: Options;
11
7
  export declare const mdProcessor: import("unified").Processor<Root, undefined, undefined, Root, string>;
@@ -7,18 +7,6 @@ import remarkStringify, {} from 'remark-stringify';
7
7
  import { unified } from 'unified';
8
8
  import { red } from 'yoctocolors';
9
9
  export const RELATIVE_URL_PATTERN = /^\.\.?\//;
10
- /**
11
- * hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
12
- */
13
- export const extractTextAndId = (title) => {
14
- const customIdReg = /\\?\{#[^}]*\}/;
15
- const text = title.replace(customIdReg, '').trimEnd();
16
- const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
17
- return [
18
- text.replace(/\\{2}/g, '').replace(/(?:[^\\]\\([[\]]))+/g, '$1'),
19
- customId,
20
- ];
21
- };
22
10
  export const normalizeReferenceItems = (items = []) => items.reduce((acc, curr) => {
23
11
  for (const source of curr.sources) {
24
12
  if (source.name in acc) {
@@ -0,0 +1 @@
1
+ export declare const PUNCTUATION_REGEX: RegExp;
@@ -0,0 +1 @@
1
+ export const PUNCTUATION_REGEX = /\p{P}/u;
@@ -0,0 +1,17 @@
1
+ import type { Root } from 'mdast';
2
+ import type { Plugin } from 'unified';
3
+ export * from './list-item-punctuation.ts';
4
+ export * from './list-item-size.ts';
5
+ export * from './list-table-introduction.ts';
6
+ export * from './maximum-link-content-length.ts';
7
+ export * from './no-deep-heading.ts';
8
+ export * from './no-deep-list.ts';
9
+ export * from './no-empty-table-cell.ts';
10
+ export * from './no-heading-punctuation.ts';
11
+ export * from './no-heading-special-characters.ts';
12
+ export * from './no-heading-sup-sub.ts';
13
+ export * from './no-paragraph-indent.ts';
14
+ export * from './table-size.ts';
15
+ export * from './unit-case.ts';
16
+ declare const doomLint: Plugin<[], Root>;
17
+ export default doomLint;
@@ -0,0 +1,21 @@
1
+ import remarkMessageControl from 'remark-message-control';
2
+ export * from "./list-item-punctuation.js";
3
+ export * from "./list-item-size.js";
4
+ export * from "./list-table-introduction.js";
5
+ export * from "./maximum-link-content-length.js";
6
+ export * from "./no-deep-heading.js";
7
+ export * from "./no-deep-list.js";
8
+ export * from "./no-empty-table-cell.js";
9
+ export * from "./no-heading-punctuation.js";
10
+ export * from "./no-heading-special-characters.js";
11
+ export * from "./no-heading-sup-sub.js";
12
+ export * from "./no-paragraph-indent.js";
13
+ export * from "./table-size.js";
14
+ export * from "./unit-case.js";
15
+ const doomLint = function () {
16
+ this.use(() => remarkMessageControl({
17
+ name: 'lint',
18
+ source: ['doom-lint', 'remark-lint'],
19
+ }));
20
+ };
21
+ export default doomLint;
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const listItemPunctuation: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,72 @@
1
+ import { toString } from 'mdast-util-to-string';
2
+ import { lintRule } from 'unified-lint-rule';
3
+ import { visitParents } from 'unist-util-visit-parents';
4
+ import { PUNCTUATION_REGEX } from "./constants.js";
5
+ const ALLOWED_PUNCTUATIONS = new Set([';', '.']);
6
+ export const listItemPunctuation = lintRule('doom-lint:list-item-punctuation', (root, vfile) => {
7
+ visitParents(root, 'list', (list, parents) => {
8
+ const listItems = list.children;
9
+ if (listItems.length < 2) {
10
+ return;
11
+ }
12
+ const firstItem = listItems[0];
13
+ const last = firstItem.children.at(-1);
14
+ if (last?.type !== 'paragraph' || last.children.at(-1)?.type !== 'text') {
15
+ return;
16
+ }
17
+ const firstItemText = toString(firstItem);
18
+ const firstItemLastChar = firstItemText.slice(-1);
19
+ const isPunctuation = ![')', ']'].includes(firstItemLastChar) &&
20
+ PUNCTUATION_REGEX.test(firstItemLastChar);
21
+ if (isPunctuation && !ALLOWED_PUNCTUATIONS.has(firstItemLastChar)) {
22
+ vfile.message(`Unexpected list item "${firstItemText}" ends with a punctuation mark "${firstItemLastChar}", remove it`, {
23
+ ancestors: [...parents, list, firstItem],
24
+ place: firstItem.position,
25
+ });
26
+ return;
27
+ }
28
+ const size = listItems.length - 1;
29
+ for (const [index, item] of listItems.slice(1).entries()) {
30
+ const last = item.children.at(-1);
31
+ if (!last ||
32
+ last.type !== 'paragraph' ||
33
+ last.children.at(-1)?.type !== 'text') {
34
+ continue;
35
+ }
36
+ const text = toString(item);
37
+ const lastChar = text.slice(-1);
38
+ if (isPunctuation) {
39
+ if (index === size - 1) {
40
+ if (lastChar !== '.') {
41
+ if ((lastChar === ')' && text.includes('(')) ||
42
+ (lastChar === ']' && text.includes('[')) ||
43
+ text.slice(-2) === '."' ||
44
+ text.slice(-2) === ".'") {
45
+ continue;
46
+ }
47
+ vfile.message(`Last list item "${text}" ends with a punctuation mark "${lastChar}" which should be a period (.) instead`, {
48
+ ancestors: [...parents, list, item],
49
+ place: item.position,
50
+ });
51
+ }
52
+ }
53
+ else if (lastChar !== firstItemLastChar) {
54
+ vfile.message(`list item "${text}" ends with a punctuation mark "${lastChar}", which does not match the first item "${firstItemText}"`, {
55
+ ancestors: [...parents, list, item],
56
+ place: item.position,
57
+ });
58
+ }
59
+ }
60
+ else if (PUNCTUATION_REGEX.test(lastChar)) {
61
+ if ((lastChar === ')' && text.includes('(')) ||
62
+ (lastChar === ']' && text.includes('['))) {
63
+ continue;
64
+ }
65
+ vfile.message(`List item "${text}" ends with a punctuation mark "${lastChar}", remove it`, {
66
+ ancestors: [...parents, list, item],
67
+ place: item.position,
68
+ });
69
+ }
70
+ }
71
+ });
72
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const listItemSize: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,15 @@
1
+ import { lintRule } from 'unified-lint-rule';
2
+ import { visitParents } from 'unist-util-visit-parents';
3
+ const MAX_LIST_ITEM_SIZE = 10;
4
+ export const listItemSize = lintRule('doom-lint:list-item-size', (root, vfile) => {
5
+ visitParents(root, 'list', (list, parents) => {
6
+ const size = list.children.length;
7
+ if (size > MAX_LIST_ITEM_SIZE) {
8
+ vfile.message(`List should have at most ${MAX_LIST_ITEM_SIZE} items, but found ${size}`, {
9
+ ancestors: [...parents, list],
10
+ place: list.position,
11
+ });
12
+ return;
13
+ }
14
+ });
15
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const listTableIntroduction: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,17 @@
1
+ import { lintRule } from 'unified-lint-rule';
2
+ import { visitParents } from 'unist-util-visit-parents';
3
+ export const listTableIntroduction = lintRule('doom-lint:list-table-introduction', (root, vfile) => {
4
+ visitParents(root, ['list', 'table'], (node_, parents) => {
5
+ const node = node_;
6
+ const parent = parents[parents.length - 1];
7
+ const index = parent.children.indexOf(node);
8
+ const prevSibling = parent.children[index - 1];
9
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
10
+ if (!prevSibling || prevSibling.type === 'heading') {
11
+ vfile.message(`There should be some introductory text before ${node.type}s`, {
12
+ ancestors: [...parents, node],
13
+ place: node.position,
14
+ });
15
+ }
16
+ });
17
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const maximumLinkContentLength: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,29 @@
1
+ import stringWidth from 'string-width';
2
+ import { lintRule } from 'unified-lint-rule';
3
+ import { visit } from 'unist-util-visit';
4
+ import { visitParents } from 'unist-util-visit-parents';
5
+ import { extractTextAndId } from "../shared/helpers.js";
6
+ const MAX_LENGTH = 40;
7
+ export const maximumLinkContentLength = lintRule('doom-lint:maximum-link-content-length', (root, vfile) => {
8
+ visit(root, ['link', 'lintReference'], (node_) => {
9
+ const node = node_;
10
+ visitParents(node, 'text', (text, parents) => {
11
+ let value = text.value;
12
+ try {
13
+ new URL(value);
14
+ return;
15
+ }
16
+ catch {
17
+ ;
18
+ [value] = extractTextAndId(value);
19
+ }
20
+ const length = stringWidth(value);
21
+ if (length > MAX_LENGTH) {
22
+ vfile.message(`Link content length \`${length}\` of \`${value}\` is too long, maximum is ${MAX_LENGTH} characters, please shorten it`, {
23
+ ancestors: [...parents, text],
24
+ place: text.position,
25
+ });
26
+ }
27
+ });
28
+ });
29
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const noDeepHeading: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,13 @@
1
+ import { lintRule } from 'unified-lint-rule';
2
+ import { visitParents } from 'unist-util-visit-parents';
3
+ const MAX_HEADING_DEPTH = 5;
4
+ export const noDeepHeading = lintRule('doom-lint:no-deep-heading', (root, vfile) => {
5
+ visitParents(root, 'heading', (heading, parents) => {
6
+ if (heading.depth > MAX_HEADING_DEPTH) {
7
+ vfile.message(`Unexpected deep heading level ${heading.depth}, maximum is ${MAX_HEADING_DEPTH}`, {
8
+ ancestors: [...parents, heading],
9
+ place: heading.position,
10
+ });
11
+ }
12
+ });
13
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const noDeepList: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,14 @@
1
+ import { lintRule } from 'unified-lint-rule';
2
+ import { visitParents } from 'unist-util-visit-parents';
3
+ const MAX_LIST_DEPTH = 4;
4
+ export const noDeepList = lintRule('doom-lint:no-deep-list', (root, vfile) => {
5
+ visitParents(root, 'list', (list, parents) => {
6
+ const depth = parents.filter((p) => p.type === 'list').length + 1;
7
+ if (depth > MAX_LIST_DEPTH) {
8
+ vfile.message(`Unexpected list depth ${depth}, maximum is ${MAX_LIST_DEPTH}`, {
9
+ ancestors: [...parents, list],
10
+ place: list.position,
11
+ });
12
+ }
13
+ });
14
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const noEmptyTableCell: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,12 @@
1
+ import { lintRule } from 'unified-lint-rule';
2
+ import { visitParents } from 'unist-util-visit-parents';
3
+ export const noEmptyTableCell = lintRule('doom-lint:no-empty-table-cell', (root, vfile) => {
4
+ visitParents(root, 'tableCell', (tableCell, parents) => {
5
+ if (!tableCell.children.length) {
6
+ vfile.message('Table cell cannot be empty, please add some content', {
7
+ ancestors: [...parents, tableCell],
8
+ place: tableCell.position,
9
+ });
10
+ }
11
+ });
12
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const noHeadingPunctuation: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,28 @@
1
+ import path from 'node:path';
2
+ import { toString } from 'mdast-util-to-string';
3
+ import { lintRule } from 'unified-lint-rule';
4
+ import { visitParents } from 'unist-util-visit-parents';
5
+ import { PUNCTUATION_REGEX } from "./constants.js";
6
+ const QUESTION_MARKS = new Set(['?', '?']);
7
+ export const noHeadingPunctuation = lintRule('doom-lint:no-heading-punctuation', (root, vfile) => {
8
+ const filename = path.basename(vfile.path, path.extname(vfile.path));
9
+ visitParents(root, 'heading', (heading, parents) => {
10
+ const text = toString(heading);
11
+ const tail = text.slice(-1);
12
+ if (PUNCTUATION_REGEX.test(tail)) {
13
+ if (filename === 'faq' && QUESTION_MARKS.has(tail)) {
14
+ return;
15
+ }
16
+ if ((tail === '}' && text.includes('{')) ||
17
+ (tail === ']' && text.includes('[')) ||
18
+ (tail === '>' && text.includes('<')) ||
19
+ (tail === ')' && text.includes('('))) {
20
+ return;
21
+ }
22
+ vfile.message(`Unexpected character \`${tail}\` at end of heading, remove it`, {
23
+ ancestors: [...parents, heading],
24
+ place: heading.position,
25
+ });
26
+ }
27
+ });
28
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const noHeadingSpecialCharacters: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,26 @@
1
+ import pluralize from 'pluralize';
2
+ import { lintRule } from 'unified-lint-rule';
3
+ import { visit } from 'unist-util-visit';
4
+ import { visitParents } from 'unist-util-visit-parents';
5
+ const SPECIAL_CHARACTER = /[*+/^|~]/;
6
+ export const noHeadingSpecialCharacters = lintRule('doom-lint:no-heading-special-characters', (root, vfile) => {
7
+ visit(root, 'heading', (heading) => {
8
+ visitParents(heading, 'text', (text, parents) => {
9
+ const pos = text.position;
10
+ const raw = String(vfile.value).slice(pos.start.offset, pos.end.offset);
11
+ const matched = [
12
+ ...new Set(raw
13
+ .split('')
14
+ .filter((it, index) => (!index || raw[index - 1] !== '\\') &&
15
+ SPECIAL_CHARACTER.test(it))),
16
+ ];
17
+ const matchedLength = matched.length;
18
+ if (matchedLength) {
19
+ vfile.message(`Unexpected special ${pluralize('character', matchedLength)} \`${matched.join('`, `')}\` contain${matchedLength === 1 ? 's' : ''} in heading text \`${raw}\`, remove it or use escape character \`\\\` to ignore it`, {
20
+ ancestors: [...parents, heading],
21
+ place: heading.position,
22
+ });
23
+ }
24
+ });
25
+ });
26
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const noHeadingSupSub: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,16 @@
1
+ import { lintRule } from 'unified-lint-rule';
2
+ import { visit } from 'unist-util-visit';
3
+ import { visitParents } from 'unist-util-visit-parents';
4
+ const SUP_SUB_REGEX = /<\/?(?:sup|sub)>/;
5
+ export const noHeadingSupSub = lintRule('doom-lint:no-heading-sup-sub', (root, vfile) => {
6
+ visit(root, 'heading', (heading) => {
7
+ visitParents(heading, 'html', (html, parents) => {
8
+ if (SUP_SUB_REGEX.test(html.value)) {
9
+ vfile.message(`Unexpected \`${html.value}\` tag in heading, remove it`, {
10
+ ancestors: [...parents, html],
11
+ place: html.position,
12
+ });
13
+ }
14
+ });
15
+ });
16
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const noParagraphIndent: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,27 @@
1
+ import { phrasing } from 'mdast-util-phrasing';
2
+ import pluralize from 'pluralize';
3
+ import { lintRule } from 'unified-lint-rule';
4
+ import { pointStart } from 'unist-util-position';
5
+ import { SKIP, visitParents } from 'unist-util-visit-parents';
6
+ export const noParagraphIndent = lintRule('doom-lint:no-paragraph-indent', (root, vfile) => {
7
+ visitParents(root, (node, parents) => {
8
+ // Do not walk into phrasing.
9
+ if (phrasing(node)) {
10
+ return SKIP;
11
+ }
12
+ const parent = parents.at(-1);
13
+ const start = pointStart(node);
14
+ // Note: it’s rather complex to detect what the expected indent is in block
15
+ // quotes and lists, so let’s only do directly in root for now.
16
+ if (!start ||
17
+ !parent ||
18
+ node.type !== 'paragraph' ||
19
+ parent.type !== 'root') {
20
+ return;
21
+ }
22
+ const actual = start.column - 1;
23
+ if (actual) {
24
+ vfile.message(`Unexpected \`${actual}\` ${pluralize('space', actual)} before paragraph, expected \`0\` spaces, remove \`${actual}\` ${pluralize('space', actual)}`, { ancestors: [...parents, node], place: start });
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const tableSize: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,14 @@
1
+ import { lintRule } from 'unified-lint-rule';
2
+ import { visitParents } from 'unist-util-visit-parents';
3
+ export const tableSize = lintRule('doom-lint:table-size', (root, vfile) => {
4
+ visitParents(root, 'table', (table, parents) => {
5
+ const rows = table.children.length;
6
+ const columns = table.children[0].children.length;
7
+ if (columns === 1 || rows === 1) {
8
+ vfile.message('Tables with only one row or only one column are not allowed, please use a list or add an additional row or column', {
9
+ ancestors: [...parents, table],
10
+ place: table.position,
11
+ });
12
+ }
13
+ });
14
+ });
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const unitCase: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,29 @@
1
+ import { lintRule } from 'unified-lint-rule';
2
+ import { visitParents } from 'unist-util-visit-parents';
3
+ // cspell:disable-next-line
4
+ const UNIT_CASE_REGEX = /\b\d+(?:\.\d+)?\s*([kmgtpe]i?)\b/gi;
5
+ const VALID_UNITS = new Set([
6
+ 'm',
7
+ 'k',
8
+ 'Ki',
9
+ ...['M', 'G', 'T', 'P', 'E'].flatMap((it) => [it, `${it}i`]),
10
+ ]);
11
+ const getPairUnit = (unit) => {
12
+ for (const it of VALID_UNITS) {
13
+ if (it.toLowerCase() === unit.toLowerCase()) {
14
+ return it;
15
+ }
16
+ }
17
+ };
18
+ export const unitCase = lintRule('doom-lint:unit-case', (root, vfile) => {
19
+ visitParents(root, 'text', (text, parents) => {
20
+ for (const [, unit] of text.value.matchAll(UNIT_CASE_REGEX)) {
21
+ if (!VALID_UNITS.has(unit)) {
22
+ vfile.message(`Unexpected unit case "${unit}", use "${getPairUnit(unit)}" instead`, {
23
+ ancestors: [...parents, text],
24
+ place: text.position,
25
+ });
26
+ }
27
+ }
28
+ });
29
+ });
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ plugins: any[];
3
+ };
4
+ export default _default;
@@ -0,0 +1,58 @@
1
+ import remarkDirective from 'remark-directive';
2
+ import remarkFrontmatter from 'remark-frontmatter';
3
+ import remarkGfm from 'remark-gfm';
4
+ // @ts-expect-error -- https://github.com/ilyatitovich/remark-lint-code-block-split-list/issues/2
5
+ import remarkLintCodeBlockSplitList from 'remark-lint-code-block-split-list';
6
+ import remarkLintHeadingIncrement from 'remark-lint-heading-increment';
7
+ // @ts-expect-error -- https://github.com/laysent/remark-lint-plugins/issues/51
8
+ import remarkLintLintMatchPunctuation from 'remark-lint-match-punctuation';
9
+ // import remarkLintMaximumHeadingLength, {
10
+ // type Options,
11
+ // } from 'remark-lint-maximum-heading-length'
12
+ // @ts-expect-error -- https://github.com/laysent/remark-lint-plugins/issues/51
13
+ import remarkLintNoChinesePunctuationInNumber from 'remark-lint-no-chinese-punctuation-in-number';
14
+ import remarkLintNoDuplicateHeadingsInSection from 'remark-lint-no-duplicate-headings-in-section';
15
+ import remarkLintNoHeadingContentIndent from 'remark-lint-no-heading-content-indent';
16
+ import remarkLintNoHeadingIndent from 'remark-lint-no-heading-indent';
17
+ import remarkLintNoHiddenTableCell from 'remark-lint-no-hidden-table-cell';
18
+ // @ts-expect-error -- https://github.com/laysent/remark-lint-plugins/issues/51
19
+ import remarkLintNoRepeatPunctuation from 'remark-lint-no-repeat-punctuation';
20
+ import doomLint, { listItemPunctuation, listItemSize, maximumLinkContentLength, noDeepHeading, noDeepList, noEmptyTableCell, noHeadingPunctuation, noHeadingSupSub, noParagraphIndent, tableSize, unitCase, } from "./remark-lint/index.js";
21
+ export default {
22
+ plugins: [
23
+ remarkDirective,
24
+ remarkFrontmatter,
25
+ remarkGfm,
26
+ remarkLintCodeBlockSplitList,
27
+ remarkLintHeadingIncrement,
28
+ remarkLintLintMatchPunctuation,
29
+ // [
30
+ // remarkLintMaximumHeadingLength,
31
+ // {
32
+ // size: 50,
33
+ // stringLength(value) {
34
+ // const [text] = extractTextAndId(value)
35
+ // return stringWidth(text)
36
+ // },
37
+ // } satisfies Options,
38
+ // ],
39
+ remarkLintNoChinesePunctuationInNumber,
40
+ remarkLintNoDuplicateHeadingsInSection,
41
+ remarkLintNoHeadingContentIndent,
42
+ remarkLintNoHeadingIndent,
43
+ remarkLintNoHiddenTableCell,
44
+ remarkLintNoRepeatPunctuation,
45
+ doomLint,
46
+ listItemPunctuation,
47
+ listItemSize,
48
+ maximumLinkContentLength,
49
+ noDeepHeading,
50
+ noDeepList,
51
+ noEmptyTableCell,
52
+ noHeadingPunctuation,
53
+ noHeadingSupSub,
54
+ noParagraphIndent,
55
+ tableSize,
56
+ unitCase,
57
+ ],
58
+ };
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Link, renderInlineMarkdown, useSidebarData } from '@rspress/core/theme';
3
- import { isEqualPath, normalizeHrefInRuntime as normalizeHref, usePageData, withBase, } from '@rspress/runtime';
3
+ import { isEqualPath, normalizeHrefInRuntime as normalizeHref, usePageData, } from '@rspress/runtime';
4
4
  import { Fragment, useCallback, useMemo } from 'react';
5
5
  import classes from '../../../styles/overview.module.scss';
6
- import { findItemByRoutePath } from './_utils.js';
6
+ import { findItemByRoutePath, isSidebarDivider, isSidebarSectionHeader, isSingleFile, } from './_utils.js';
7
7
  const getChildLink = (traverseItem) => {
8
8
  if ('link' in traverseItem && traverseItem.link) {
9
9
  return traverseItem.link;
@@ -22,8 +22,8 @@ export function Overview(props) {
22
22
  const subFilter = useCallback((link) =>
23
23
  // sidebar items link without base path
24
24
  // pages route path with base path
25
- withBase(link).startsWith(routePath.replace(/overview$/, '')) &&
26
- !isEqualPath(withBase(link), routePath), [routePath]);
25
+ link.startsWith(routePath.replace(/overview$/, '')) &&
26
+ !isEqualPath(link, routePath), [routePath]);
27
27
  const { pages } = siteData;
28
28
  const overviewModules = useMemo(() => pages.filter((page) => subFilter(page.routePath)), [pages, subFilter]);
29
29
  let overviewSidebarGroups = useSidebarData();
@@ -33,12 +33,11 @@ export function Overview(props) {
33
33
  overviewSidebarGroups = findItemByRoutePath(overviewSidebarGroups, routePath);
34
34
  }
35
35
  const normalizeSidebarItem = useCallback((item, sidebarGroup, frontmatter) => {
36
- if ('dividerType' in item) {
37
- return item;
36
+ if (isSidebarDivider(item) || isSidebarSectionHeader(item)) {
37
+ return false;
38
38
  }
39
39
  // do not display overview title in sub pages overview
40
- if (withBase(item.link) === `${routePath}index` &&
41
- frontmatter?.overview === true) {
40
+ if (item.link === `${routePath}index` && frontmatter?.overview === true) {
42
41
  return false;
43
42
  }
44
43
  // props > frontmatter in single file > _meta.json config in a file > frontmatter in overview page > _meta.json config in sidebar
@@ -47,7 +46,7 @@ export function Overview(props) {
47
46
  frontmatter?.overviewHeaders ??
48
47
  sidebarGroup?.overviewHeaders ?? [2];
49
48
  // sidebar items link without base path
50
- const pageModule = overviewModules.find((m) => isEqualPath(m.routePath, withBase(item.link || '')));
49
+ const pageModule = overviewModules.find((m) => isEqualPath(m.routePath, item.link || ''));
51
50
  const link = getChildLink(item);
52
51
  return {
53
52
  ...item,
@@ -56,7 +55,6 @@ export function Overview(props) {
56
55
  headers: pageModule?.toc.filter((header) => overviewHeaders.some((depth) => header.depth === depth)) || [],
57
56
  };
58
57
  }, [overviewModules, props.overviewHeaders, routePath]);
59
- const isSingleFile = (item) => !('items' in item) && 'link' in item;
60
58
  const getGroup = useCallback((sidebarGroups) => {
61
59
  const group = sidebarGroups
62
60
  .filter((sidebarGroup) => {
@@ -75,7 +73,7 @@ export function Overview(props) {
75
73
  if ('items' in sidebarGroup) {
76
74
  items = sidebarGroup.items
77
75
  .map((item) => normalizeSidebarItem(item, sidebarGroup, frontmatter))
78
- .filter((_) => !!_);
76
+ .filter(Boolean);
79
77
  }
80
78
  else if (isSingleFile(sidebarGroup)) {
81
79
  items = [
@@ -86,7 +84,7 @@ export function Overview(props) {
86
84
  _fileKey: sidebarGroup._fileKey,
87
85
  overviewHeaders: sidebarGroup.overviewHeaders,
88
86
  }, undefined, frontmatter),
89
- ].filter((_) => !!_);
87
+ ].filter(Boolean);
90
88
  }
91
89
  return {
92
90
  name: ('text' in sidebarGroup && sidebarGroup.text) || '',
@@ -1,7 +1,11 @@
1
1
  import type { NormalizedSidebarGroup, SidebarDivider, SidebarItem, SidebarSectionHeader } from '@rspress/shared';
2
2
  export declare const isSidebarDivider: (item: NormalizedSidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader) => item is SidebarDivider;
3
+ export declare const isSidebarSectionHeader: (item: NormalizedSidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader) => item is SidebarSectionHeader;
4
+ export declare const isSingleFile: (item: SidebarItem | SidebarSectionHeader | SidebarDivider | NormalizedSidebarGroup) => item is SidebarItem | (NormalizedSidebarGroup & {
5
+ link: string;
6
+ });
3
7
  /**
4
8
  * @zh_CN 如果 index 在 sidebar items 中, 则返回所有平级 item, 如果 index 在 dir 上, 则返回 items
5
9
  * @example
6
10
  */
7
- export declare function findItemByRoutePath(items: (SidebarItem | NormalizedSidebarGroup | SidebarDivider)[], routePath: string): (SidebarItem | NormalizedSidebarGroup)[];
11
+ export declare function findItemByRoutePath(items: (SidebarItem | SidebarSectionHeader | NormalizedSidebarGroup | SidebarDivider)[], routePath: string): (SidebarItem | NormalizedSidebarGroup)[];
@@ -8,13 +8,17 @@ function removeIndex(link) {
8
8
  export const isSidebarDivider = (item) => {
9
9
  return 'dividerType' in item;
10
10
  };
11
+ export const isSidebarSectionHeader = (item) => {
12
+ return 'sectionHeaderText' in item;
13
+ };
14
+ export const isSingleFile = (item) => !('items' in item) && 'link' in item;
11
15
  /**
12
16
  * @zh_CN 如果 index 在 sidebar items 中, 则返回所有平级 item, 如果 index 在 dir 上, 则返回 items
13
17
  * @example
14
18
  */
15
19
  export function findItemByRoutePath(items, routePath) {
16
20
  function isRoutePathMatch(item) {
17
- if (isSidebarDivider(item)) {
21
+ if (isSidebarDivider(item) || isSidebarSectionHeader(item)) {
18
22
  return false;
19
23
  }
20
24
  const withBaseUrl = withBase(item.link);
@@ -1,7 +1,8 @@
1
- import { isProduction, usePageData } from '@rspress/core/runtime';
1
+ import { isProduction } from '@rspress/core/runtime';
2
2
  import virtual from 'doom-@global-virtual';
3
3
  import { merge } from 'es-toolkit/compat';
4
4
  import { useEffect, useMemo, useState } from 'react';
5
+ import { base } from 'virtual-runtime-config';
5
6
  import { parse } from 'yaml';
6
7
  import { isUnversioned } from '../../shared/index.js';
7
8
  import { namedTerms } from '../../terms.js';
@@ -26,7 +27,7 @@ const fetchSiteOverrides = async (base, version, acpSite) => {
26
27
  const acpSiteOverridesUrl = acpSite && isProduction()
27
28
  ? `${(virtual.prefix || '') + acpSite.base}${isUnversioned(version) ? '' : acpSite.version + '/'}overrides.yaml`
28
29
  : null;
29
- const siteOverridesUrl = `${isProduction() ? base : '/'}overrides.yaml`;
30
+ const siteOverridesUrl = `${base}/overrides.yaml`;
30
31
  const urls = [acpSiteOverridesUrl];
31
32
  if (acpSiteOverridesUrl !== siteOverridesUrl) {
32
33
  urls.push(siteOverridesUrl);
@@ -62,7 +63,6 @@ const fetchSiteOverrides = async (base, version, acpSite) => {
62
63
  }));
63
64
  };
64
65
  export const useSiteOverrides = () => {
65
- const { siteData } = usePageData();
66
66
  const [siteOverrides, setSiteOverrides] = useState(normalizedSiteOverrides);
67
67
  const lang = useLang();
68
68
  const acpSite = useMemo(() => virtual.sites?.find((s) => s.name === 'acp'), []);
@@ -70,7 +70,7 @@ export const useSiteOverrides = () => {
70
70
  if (normalizedSiteOverrides) {
71
71
  return;
72
72
  }
73
- void fetchSiteOverrides(siteData.base, virtual.version, acpSite).then(setSiteOverrides);
74
- }, [acpSite, siteData.base]);
73
+ void fetchSiteOverrides(base, virtual.version, acpSite).then(setSiteOverrides);
74
+ }, [acpSite]);
75
75
  return siteOverrides?.[lang] || {};
76
76
  };
@@ -1,6 +1,13 @@
1
- import type { UnversionedVersion } from './types.js';
1
+ import { type NavItemWithLink } from '@rspress/shared';
2
+ import type { UnversionedVersion } from './types.ts';
2
3
  export declare const removeBothEndsSlashes: (str?: string) => string;
3
4
  export declare const getPdfName: (lang: string, userBase?: string, title?: string) => string;
4
5
  export declare const isExplicitlyUnversioned: (version?: string) => version is UnversionedVersion;
5
6
  export declare const isUnversioned: (version?: string) => version is undefined | "" | UnversionedVersion;
6
7
  export declare const getUnversionedVersion: (version?: string) => string | undefined;
8
+ /**
9
+ * hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
10
+ */
11
+ export declare const extractTextAndId: (title: string) => string[];
12
+ export declare const withoutBase: (path: string, base: string) => string;
13
+ export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string, base: string) => boolean;
@@ -1,4 +1,5 @@
1
- import { UNVERSIONED, UNVERSIONED_PREFIX } from './constants.js';
1
+ import { addLeadingSlash, normalizeSlash, } from '@rspress/shared';
2
+ import { UNVERSIONED, UNVERSIONED_PREFIX } from "./constants.js";
2
3
  export const removeBothEndsSlashes = (str) => str?.replace(/^\/|\/$/g, '') || '';
3
4
  export const getPdfName = (lang, userBase, title) => `${removeBothEndsSlashes(userBase) || title || 'exported'}-${lang}.pdf`;
4
5
  export const isExplicitlyUnversioned = (version) => version === UNVERSIONED || !!version?.startsWith(UNVERSIONED_PREFIX);
@@ -11,3 +12,17 @@ export const getUnversionedVersion = (version) => {
11
12
  ? version.slice(UNVERSIONED_PREFIX.length)
12
13
  : version;
13
14
  };
15
+ /**
16
+ * hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
17
+ */
18
+ export const extractTextAndId = (title) => {
19
+ const customIdReg = /\\?\{#[^}]*\}/;
20
+ const text = title.replace(customIdReg, '').trimEnd();
21
+ const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
22
+ return [
23
+ text.replace(/\\{2}/g, '').replace(/(?:[^\\]\\([[\]]))+/g, '$1'),
24
+ customId,
25
+ ];
26
+ };
27
+ export const withoutBase = (path, base) => addLeadingSlash(path).replace(normalizeSlash(base), '');
28
+ export const matchNavbar = (item, currentPathname, base) => new RegExp(item.activeMatch || item.link).test(withoutBase(currentPathname, base));
@@ -1,4 +1,4 @@
1
- import type { UNVERSIONED } from './constants.js';
1
+ import type { UNVERSIONED } from './constants.ts';
2
2
  export interface DoomSite {
3
3
  name: string;
4
4
  base: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.8.1",
3
+ "version": "1.9.1",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "git+https://github.com/alauda/doom.git",
@@ -36,57 +36,74 @@
36
36
  "rspress-plugins"
37
37
  ],
38
38
  "dependencies": {
39
- "@cspell/eslint-plugin": "^8.19.4 || ^9.1.1",
39
+ "@cspell/eslint-plugin": "^8.19.4 || ^9.1.3",
40
40
  "@eslint-react/eslint-plugin": "^1.52.2",
41
- "@inquirer/prompts": "^7.5.3",
41
+ "@inquirer/prompts": "^7.6.0",
42
42
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
43
- "@playwright/browser-chromium": "^1.53.1",
44
- "@rsbuild/plugin-react": "^1.3.2",
45
- "@rsbuild/plugin-sass": "^1.3.2",
46
- "@rsbuild/plugin-svgr": "^1.2.0",
43
+ "@playwright/browser-chromium": "^1.53.2",
44
+ "@rsbuild/plugin-react": "^1.3.4",
45
+ "@rsbuild/plugin-sass": "^1.3.3",
46
+ "@rsbuild/plugin-svgr": "^1.2.1",
47
47
  "@rsbuild/plugin-yaml": "^1.0.2",
48
- "@rspress/core": "2.0.0-beta.14",
49
- "@rspress/plugin-algolia": "2.0.0-beta.14",
50
- "@rspress/plugin-llms": "2.0.0-beta.14",
51
- "@shikijs/transformers": "^3.6.0",
48
+ "@rspress/core": "2.0.0-beta.20",
49
+ "@rspress/plugin-algolia": "2.0.0-beta.20",
50
+ "@rspress/plugin-llms": "2.0.0-beta.20",
51
+ "@shikijs/transformers": "^3.7.0",
52
52
  "@total-typescript/ts-reset": "^0.6.1",
53
53
  "chokidar": "^4.0.3",
54
54
  "cli-progress": "^3.12.0",
55
55
  "clsx": "^2.1.1",
56
56
  "commander": "^13.1.0 || ^14.0.0",
57
57
  "ejs": "^3.1.10",
58
- "es-toolkit": "^1.39.3",
59
- "eslint": "^9.29.0",
60
- "eslint-plugin-mdx": "^3.5.0",
61
- "globals": "^16.2.0",
58
+ "es-toolkit": "^1.39.7",
59
+ "eslint": "^9.30.1",
60
+ "eslint-plugin-mdx": "^3.6.2",
61
+ "globals": "^16.3.0",
62
62
  "html-tag-names": "^2.1.0",
63
63
  "md-attr-parser": "^1.3.0",
64
64
  "mdast-util-mdx": "^3.0.0",
65
65
  "mdast-util-mdx-jsx": "^3.2.0",
66
- "mermaid": "^11.6.0",
67
- "openai": "^5.5.1",
66
+ "mdast-util-phrasing": "^4.1.0",
67
+ "mdast-util-to-string": "^4.0.0",
68
+ "mermaid": "^11.8.1",
69
+ "openai": "^5.8.3",
68
70
  "openapi-types": "^12.1.3",
69
71
  "p-ratelimit": "^1.0.1",
70
72
  "pdf-lib": "^1.17.1",
71
73
  "pdf-merger-js": "^5.1.2",
72
74
  "picomatch": "^4.0.2",
73
- "playwright": "^1.53.1",
75
+ "playwright": "^1.53.2",
76
+ "pluralize": "^8.0.0",
74
77
  "react-markdown": "^10.1.0",
75
78
  "rehype-raw": "^7.0.0",
76
79
  "rehype-sanitize": "^6.0.0",
77
80
  "remark-directive": "^4.0.0",
78
81
  "remark-frontmatter": "^5.0.0",
79
82
  "remark-gfm": "^4.0.1",
83
+ "remark-lint-code-block-split-list": "^1.0.0",
84
+ "remark-lint-heading-increment": "^4.0.1",
85
+ "remark-lint-match-punctuation": "^0.2.1",
86
+ "remark-lint-no-chinese-punctuation-in-number": "^0.1.2",
87
+ "remark-lint-no-duplicate-headings-in-section": "^4.0.1",
88
+ "remark-lint-no-heading-content-indent": "^5.0.1",
89
+ "remark-lint-no-heading-indent": "^5.0.1",
90
+ "remark-lint-no-hidden-table-cell": "^1.0.1",
91
+ "remark-lint-no-repeat-punctuation": "^0.1.4",
80
92
  "remark-mdx": "^3.1.0",
93
+ "remark-message-control": "^8.0.0",
81
94
  "remark-stringify": "^11.0.0",
82
- "shiki": "^3.6.0",
95
+ "shiki": "^3.7.0",
83
96
  "simple-git": "^3.28.0",
97
+ "string-width": "^7.2.0",
84
98
  "swagger2openapi": "^7.0.8",
85
99
  "tinyglobby": "^0.2.14",
86
100
  "type-fest": "^4.41.0",
87
101
  "typescript": "^5.8.3",
88
- "typescript-eslint": "^8.34.1",
102
+ "typescript-eslint": "^8.36.0",
89
103
  "unified": "^11.0.5",
104
+ "unified-lint-rule": "^3.0.1",
105
+ "unist-util-position": "^5.0.0",
106
+ "unist-util-visit-parents": "^6.0.1",
90
107
  "x-fetch": "^0.2.6",
91
108
  "yaml": "^2.8.0",
92
109
  "yoctocolors": "^2.1.1"
@@ -50,7 +50,7 @@
50
50
  "ws": false
51
51
  },
52
52
  "dependencies": {
53
- "ws": "^8.18.2"
53
+ "ws": "^8.18.3"
54
54
  },
55
55
  "types": "./pyodide.d.ts",
56
56
  "engines": {
@@ -146,13 +146,13 @@ td {
146
146
  @include print;
147
147
  }
148
148
 
149
- .rp-list-decimal {
149
+ .rp-list-decimal:not(:has(p)) {
150
150
  list-style: none;
151
151
  counter-reset: section;
152
152
  padding-left: 20px;
153
- }
154
153
 
155
- .rp-list-decimal > li:before {
156
- counter-increment: section;
157
- content: counters(section, '.') '. ';
154
+ > li:before {
155
+ counter-increment: section;
156
+ content: counters(section, '.') '. ';
157
+ }
158
158
  }