@alauda/doom 0.22.4 → 0.22.5

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.
@@ -6,3 +6,4 @@ export declare const getMatchedDocFilePaths: (matched: string[]) => Promise<(str
6
6
  * {@link https://github.com/web-infra-dev/rspress/blob/f3e6544780a371d7c629d8784f31dbcf28fb2b07/packages/core/src/node/utils/escapeHeadingIds.ts}
7
7
  */
8
8
  export declare function escapeMarkdownHeadingIds(content: string): string;
9
+ export declare const defaultGitHubUrl: (url: string) => string;
@@ -29,3 +29,6 @@ export function escapeMarkdownHeadingIds(content) {
29
29
  // prevent duplicate escaping
30
30
  .replace('\\\\{#', '\\{#'));
31
31
  }
32
+ export const defaultGitHubUrl = (url) => /^https?:\/\//.test(url)
33
+ ? url
34
+ : `https://github.com/${url.replace(/^(\/*github.com)?\/+/i, '')}`;
package/lib/cli/index.js CHANGED
@@ -9,6 +9,7 @@ import { build, dev, serve } from '@rspress/core';
9
9
  import { watch } from 'chokidar';
10
10
  import { program } from 'commander';
11
11
  import { green } from 'yoctocolors';
12
+ import { FALSY_VALUES, TRUTHY_VALUES } from '../shared/index.js';
12
13
  import { setNodeEnv } from '../utils/index.js';
13
14
  import { CWD, DEFAULT_CONFIGS, I18N_FILE, SITES_FILE } from './constants.js';
14
15
  import { exportCommand } from './export.js';
@@ -40,7 +41,8 @@ program
40
41
  .option('-I, --include <language...>', 'Include **only** the specific language(s), `en ru` for example')
41
42
  .option('-E, --exclude <language...>', 'Include all languages except the specific language(s), `ru` for example')
42
43
  .option('-o, --out-dir <path>', 'Override the `outDir` defined in the config file or the default `dist/{base}/{version}`, the resulting path will be `dist/{outDir}/{version}`')
43
- .option('-r, --redirect <enum>', 'Whether to redirect to the locale closest to `navigator.language` when the user visits the site, could be `auto` or `never`', 'auto')
44
+ .option('-r, --redirect <enum>', 'Whether to redirect to the locale closest to `navigator.language` when the user visits the site, could be `auto`, `never` or `only-default-lang`', 'only-default-lang')
45
+ .option('-R, --edit-repo [boolean|url]', 'Whether to enable or override the `editRepoBaseUrl` config feature, `https://github.com/` prefix could be omitted', (value) => FALSY_VALUES.has(value) ? false : TRUTHY_VALUES.has(value) || value, false)
44
46
  .option('-n, --no-open [boolean]', 'Do not open the browser after starting the server')
45
47
  .command('dev', { isDefault: true })
46
48
  .description('Start the development server')
@@ -1,6 +1,6 @@
1
1
  import { type UserConfig } from '@rspress/core';
2
2
  import type { GlobalCliOptions } from '../types.js';
3
- export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, }?: GlobalCliOptions): Promise<{
3
+ export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, editRepo, }?: GlobalCliOptions): Promise<{
4
4
  config: UserConfig;
5
5
  filepath?: string;
6
6
  }>;
@@ -7,15 +7,20 @@ import { logger } from '@rspress/shared/logger';
7
7
  import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
8
8
  import { difference } from 'es-toolkit';
9
9
  import rehypeRaw from 'rehype-raw';
10
+ import { cyan } from 'yoctocolors';
10
11
  import { autoTocPlugin } from '../plugins/auto-toc/index.js';
11
12
  import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, replacePlugin, shikiPlugin, } from '../plugins/index.js';
12
13
  import { isExplicitlyUnversioned, UNVERSIONED, } from '../shared/index.js';
13
14
  import { pathExists, pkgResolve, resolveStaticConfig } from '../utils/index.js';
14
15
  import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
16
+ import { defaultGitHubUrl } from './helpers.js';
15
17
  const DEFAULT_LOGO = '/logo.svg';
16
18
  const KNOWN_LOCALE_CONFIGS = {
17
19
  en: {
18
20
  label: 'English',
21
+ editLink: {
22
+ text: '📝 Edit this page on GitHub',
23
+ },
19
24
  },
20
25
  zh: {
21
26
  label: '简体中文',
@@ -25,6 +30,9 @@ const KNOWN_LOCALE_CONFIGS = {
25
30
  outlineTitle: '本页概览',
26
31
  prevPageText: '上一页',
27
32
  nextPageText: '下一页',
33
+ editLink: {
34
+ text: '📝 在 GitHub 上编辑此页',
35
+ },
28
36
  },
29
37
  ru: {
30
38
  label: 'Русский',
@@ -34,9 +42,12 @@ const KNOWN_LOCALE_CONFIGS = {
34
42
  outlineTitle: 'Обзор страницы',
35
43
  prevPageText: 'Предыдущая страница',
36
44
  nextPageText: 'Следующая страница',
45
+ editLink: {
46
+ text: '📝 Редактировать эту страницу на GitHub',
47
+ },
37
48
  },
38
49
  };
39
- const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, include, exclude, redirect, }) => {
50
+ const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, include, exclude, redirect, editRepo, }) => {
40
51
  const fallbackToZh = 'lang' in config && !config.lang;
41
52
  root = resolveDocRoot(CWD, root, config.root);
42
53
  const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
@@ -44,6 +55,19 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
44
55
  if (version && !isExplicitlyUnversioned(version)) {
45
56
  base = userBase + `${version}/`;
46
57
  }
58
+ let { editRepoBaseUrl } = config;
59
+ const editRepoEnabled = !!editRepo;
60
+ if (typeof editRepo === 'string') {
61
+ editRepoBaseUrl = editRepo;
62
+ }
63
+ if (editRepoEnabled) {
64
+ if (editRepoBaseUrl) {
65
+ editRepoBaseUrl = defaultGitHubUrl(editRepoBaseUrl);
66
+ }
67
+ else {
68
+ logger.error(`The \`${cyan('-R, --edit-repo')}\` flag is enabled specifically, but no \`${cyan('editRepoBaseUrl')}\` found, it will take no effect`);
69
+ }
70
+ }
47
71
  const allLanguages = [];
48
72
  const locales = [];
49
73
  if (!fallbackToZh) {
@@ -68,10 +92,18 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
68
92
  lang: name,
69
93
  label: name,
70
94
  ...KNOWN_LOCALE_CONFIGS[name],
95
+ editLink: editRepoEnabled && editRepoBaseUrl
96
+ ? {
97
+ docRepoBaseUrl: editRepoBaseUrl,
98
+ ...KNOWN_LOCALE_CONFIGS.en.editLink,
99
+ ...KNOWN_LOCALE_CONFIGS[name]?.editLink,
100
+ }
101
+ : undefined,
71
102
  });
72
103
  }
73
104
  }
74
105
  const unusedLanguages = difference(allLanguages, locales.map(({ lang }) => lang));
106
+ const { editLink, ...zhLocale } = KNOWN_LOCALE_CONFIGS.zh;
75
107
  return {
76
108
  userBase,
77
109
  root,
@@ -103,7 +135,14 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
103
135
  // https://github.com/web-infra-dev/rspress/issues/2011
104
136
  outline: true,
105
137
  localeRedirect: redirect,
106
- ...(fallbackToZh ? KNOWN_LOCALE_CONFIGS.zh : { locales }),
138
+ ...(fallbackToZh
139
+ ? editRepoEnabled && editRepoBaseUrl
140
+ ? {
141
+ ...zhLocale,
142
+ editLink: { ...editLink, docRepoBaseUrl: editRepoBaseUrl },
143
+ }
144
+ : zhLocale
145
+ : { locales }),
107
146
  },
108
147
  plugins: [
109
148
  apiPlugin({
@@ -179,7 +218,7 @@ const findConfig = async (basePath) => {
179
218
  }
180
219
  }
181
220
  };
182
- export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, } = {}) {
221
+ export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, editRepo, } = {}) {
183
222
  let configFilePath;
184
223
  if (configFile) {
185
224
  configFilePath = path.resolve(configFile);
@@ -244,6 +283,7 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
244
283
  include,
245
284
  exclude,
246
285
  redirect,
286
+ editRepo,
247
287
  });
248
288
  base = commonConfig.base;
249
289
  const mergedConfig = mergeRsbuildConfig(commonConfig, config, {
@@ -1,6 +1,7 @@
1
1
  export declare const ACP_BASE = "/container_platform/";
2
- export declare const FALSY_VALUES: Set<string>;
3
- export declare const JS_STR_FALSY_VALUES: Set<string>;
2
+ export declare const FALSY_VALUES: Set<string | null | undefined>;
3
+ export declare const TRUTHY_VALUES: Set<string>;
4
+ export declare const JS_STR_FALSY_VALUES: Set<string | null | undefined>;
4
5
  export declare const APIS_ROUTES: Set<string>;
5
6
  export declare const Language: {
6
7
  readonly en: "英文";
@@ -1,6 +1,19 @@
1
1
  export const ACP_BASE = '/container_platform/';
2
- export const FALSY_VALUES = new Set(['', '0', 'false', 'no', 'off', 'n', 'f']);
2
+ export const FALSY_VALUES = new Set([
3
+ null,
4
+ undefined,
5
+ '',
6
+ '0',
7
+ 'false',
8
+ 'no',
9
+ 'off',
10
+ 'n',
11
+ 'f',
12
+ ]);
13
+ export const TRUTHY_VALUES = new Set(['1', 'true', 'yes', 'on', 'y', 't']);
3
14
  export const JS_STR_FALSY_VALUES = new Set([
15
+ null,
16
+ undefined,
4
17
  '',
5
18
  '0',
6
19
  'false',
package/lib/types.d.ts CHANGED
@@ -17,7 +17,8 @@ export interface GlobalCliOptions {
17
17
  include?: string[];
18
18
  exclude?: string[];
19
19
  outDir?: string;
20
- redirect?: 'auto' | 'never';
20
+ redirect?: 'auto' | 'never' | 'only-default-lang';
21
+ editRepo?: boolean | string;
21
22
  }
22
23
  export interface TranslateOptions {
23
24
  systemPrompt?: string;
@@ -36,6 +37,7 @@ declare module '@rspress/shared' {
36
37
  internalRoutes?: string[];
37
38
  translate?: TranslateOptions;
38
39
  shiki?: PluginShikiOptions;
40
+ editRepoBaseUrl?: string;
39
41
  }
40
42
  }
41
43
  export type ContentProcessor = {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.22.4",
3
+ "version": "0.22.5",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
- "repository": "git+https://github.com/alauda/Doom.git",
7
- "homepage": "https://github.com/alauda/Doom#readme",
6
+ "repository": "git+https://github.com/alauda/doom.git",
7
+ "homepage": "https://github.com/alauda/doom#readme",
8
8
  "funding": "https://opencollective.com/alauda",
9
9
  "license": "MIT",
10
10
  "engines": {
@@ -34,11 +34,11 @@
34
34
  "rspress-plugins"
35
35
  ],
36
36
  "dependencies": {
37
- "@inquirer/prompts": "^7.5.0",
37
+ "@inquirer/prompts": "^7.5.1",
38
38
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
39
39
  "@playwright/browser-chromium": "^1.52.0",
40
40
  "@rsbuild/plugin-yaml": "^1.0.2",
41
- "@rspress/core": "1.43.12",
41
+ "@rspress/core": "1.43.13",
42
42
  "@shikijs/transformers": "^3.4.0",
43
43
  "chokidar": "^4.0.3",
44
44
  "cli-progress": "^3.12.0",