@alauda/doom 1.0.0-next.2 → 1.0.0-next.3

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.
@@ -1,4 +1,4 @@
1
- export declare const parseBoolean: (value: string) => boolean;
1
+ export declare const parseBoolean: (value?: string) => boolean;
2
2
  export declare const getMatchedDocFilePaths: (matched: string[]) => Promise<(string | string[])[]>;
3
3
  /**
4
4
  * Support custom id like `#hello world {#custom-id}`
@@ -3,7 +3,7 @@ import { glob } from 'tinyglobby';
3
3
  import { xfetch } from 'x-fetch';
4
4
  import { parse } from 'yaml';
5
5
  import { FALSY_VALUES } from '../shared/index.js';
6
- export const parseBoolean = (value) => !!value && !FALSY_VALUES.has(value);
6
+ export const parseBoolean = (value) => value === undefined || !FALSY_VALUES.has(value);
7
7
  const DOC_PATTERN = /\.mdx?$/;
8
8
  const isDoc = (filename) => DOC_PATTERN.test(filename);
9
9
  export const getMatchedDocFilePaths = (matched) => Promise.all(matched.map(async (it) => {
package/lib/cli/index.js CHANGED
@@ -43,7 +43,10 @@ program
43
43
  .option('-E, --exclude <language...>', 'Include all languages except the specific language(s), `ru` for example')
44
44
  .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}`')
45
45
  .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')
46
- .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)
46
+ .option('-R, --edit-repo [boolean|url]', 'Whether to enable or override the `editRepoBaseUrl` config feature, `https://github.com/` prefix could be omitted', (value) => value === undefined ||
47
+ (FALSY_VALUES.has(value) ? false : TRUTHY_VALUES.has(value) || value), false)
48
+ .option('-a, --algolia', 'Whether to enable Algolia search', parseBoolean, false)
49
+ .option('-S, --site-url', 'Whether to enable the siteUrl for sitemap generation', parseBoolean, false)
47
50
  .option('-n, --no-open [boolean]', 'Do not open the browser after starting the server')
48
51
  .command('dev', { isDefault: true })
49
52
  .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, editRepo, }?: 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, algolia, siteUrl, }?: GlobalCliOptions): Promise<{
4
4
  config: UserConfig;
5
5
  filepath?: string;
6
6
  }>;
@@ -4,13 +4,14 @@ import { nodeTypes } from '@mdx-js/mdx';
4
4
  import { pluginSass } from '@rsbuild/plugin-sass';
5
5
  import { pluginYaml } from '@rsbuild/plugin-yaml';
6
6
  import { addLeadingSlash, addTrailingSlash, normalizeSlash, removeLeadingSlash, } from '@rspress/core';
7
+ import { pluginAlgolia } from '@rspress/plugin-algolia';
8
+ import { pluginLlms } from '@rspress/plugin-llms';
7
9
  import { logger } from '@rspress/shared/logger';
8
10
  import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
9
11
  import { difference } from 'es-toolkit';
10
12
  import rehypeRaw from 'rehype-raw';
11
13
  import { cyan } from 'yoctocolors';
12
- import { autoTocPlugin } from '../plugins/auto-toc/index.js';
13
- import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, rehypeFix, replacePlugin, } from '../plugins/index.js';
14
+ import { apiPlugin, autoSidebarPlugin, autoTocPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, rehypeFix, replacePlugin, sitemapPlugin, } from '../plugins/index.js';
14
15
  import { isExplicitlyUnversioned, UNVERSIONED, } from '../shared/index.js';
15
16
  import { pathExists, pkgResolve, resolveStaticConfig } from '../utils/index.js';
16
17
  import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
@@ -48,7 +49,7 @@ const KNOWN_LOCALE_CONFIGS = {
48
49
  },
49
50
  },
50
51
  };
51
- const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, include, exclude, redirect, editRepo, }) => {
52
+ const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, include, exclude, redirect, editRepo, algolia, siteUrl, }) => {
52
53
  const fallbackToZh = 'lang' in config && !config.lang;
53
54
  root = resolveDocRoot(CWD, root, config.root);
54
55
  const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
@@ -105,6 +106,7 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
105
106
  }
106
107
  const unusedLanguages = difference(allLanguages, locales.map(({ lang }) => lang));
107
108
  const { editLink, ...zhLocale } = KNOWN_LOCALE_CONFIGS.zh;
109
+ const algoliaOptions = algolia ? config.algolia : undefined;
108
110
  return {
109
111
  userBase,
110
112
  root,
@@ -158,6 +160,8 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
158
160
  : { locales }),
159
161
  },
160
162
  plugins: [
163
+ algoliaOptions && pluginAlgolia(),
164
+ pluginLlms(),
161
165
  apiPlugin({
162
166
  localBasePath,
163
167
  }),
@@ -174,7 +178,13 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
174
178
  localBasePath,
175
179
  force,
176
180
  }),
177
- ],
181
+ siteUrl &&
182
+ config.siteUrl &&
183
+ sitemapPlugin({
184
+ domain: config.siteUrl,
185
+ }),
186
+ ].filter(Boolean),
187
+ search: algoliaOptions ? false : undefined,
178
188
  builderConfig: {
179
189
  dev: {
180
190
  lazyCompilation: lazy,
@@ -184,12 +194,21 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
184
194
  open,
185
195
  },
186
196
  tools: {
187
- rspack: {
188
- resolve: {
189
- extensionAlias: {
190
- '.js': ['.ts', '.tsx', '.js'],
197
+ rspack(rspackConfig, { mergeConfig, rspack }) {
198
+ return mergeConfig(rspackConfig, {
199
+ resolve: {
200
+ extensionAlias: {
201
+ '.js': ['.ts', '.tsx', '.js'],
202
+ },
191
203
  },
192
- },
204
+ plugins: [
205
+ new rspack.DefinePlugin({
206
+ 'process.env.ALGOLIA_APP_ID': JSON.stringify(algoliaOptions?.appId),
207
+ 'process.env.ALGOLIA_API_KEY': JSON.stringify(algoliaOptions?.apiKey),
208
+ 'process.env.ALGOLIA_INDEX_NAME': JSON.stringify(algoliaOptions?.indexName),
209
+ }),
210
+ ],
211
+ });
193
212
  },
194
213
  },
195
214
  },
@@ -202,7 +221,7 @@ const findConfig = async (basePath) => {
202
221
  }
203
222
  }
204
223
  };
205
- export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, editRepo, } = {}) {
224
+ export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, editRepo, algolia, siteUrl, } = {}) {
206
225
  let configFilePath;
207
226
  if (configFile) {
208
227
  configFilePath = path.resolve(configFile);
@@ -268,6 +287,8 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
268
287
  exclude,
269
288
  redirect,
270
289
  editRepo,
290
+ algolia,
291
+ siteUrl,
271
292
  });
272
293
  base = commonConfig.base;
273
294
  const mergedConfig = mergeRsbuildConfig(commonConfig, config, {
@@ -50,9 +50,9 @@ const DEFAULT_SYSTEM_PROMPT = `
50
50
  - 语句不通顺,指出位置,不需要给出修改意见,意译时修复
51
51
  - 晦涩难懂,模棱两可,不易理解,可以尝试给出解释
52
52
  3. 根据第一步直译的结果和第二步指出的问题,重新进行意译,保证内容的原意的基础上,使其更易于理解,更符合<%= targetLang %>技术文档的表达习惯,同时保持原有的格式不变
53
- 4. 当存在之前翻译过的<%= targetLang %>文档时,将第三步的结果分段与之前的<%= targetLang %>文档细致地比较,不要遗漏任何新的分段(包括文本、资源链接等),如果分段内翻译结果意思相近,仅仅表达方式不同的,且没有新增任何内容时,则该分段只需要保持之前翻译过的内容即可,不需要重复翻译
53
+ 4. 当存在之前翻译过的<%= targetLang %>文档时,将第三步的结果分段与之前的<%= targetLang %>文档细致地比较,不要遗漏任何新的分段(包括文本、代码块、图片、超链接等等),如果分段内翻译结果意思相近,仅仅表达方式不同的,且没有新增任何内容时,则该分段只需要保持之前翻译过的内容即可,不需要重复翻译
54
54
 
55
- 最终只需要输出最后一步的结果,不需要输出之前步骤的结果。
55
+ 最终只需要完整输出最后一步的结果,不需要输出任何提及提示词或之前步骤的内容,也不要只返回新增的内容。
56
56
 
57
57
  <%= userPrompt %>
58
58
 
@@ -106,7 +106,7 @@ export const translate = async ({ source, sourceContent, target, targetContent =
106
106
  },
107
107
  ],
108
108
  model: 'gpt-4o-mini',
109
- temperature: 0,
109
+ temperature: 0.2,
110
110
  });
111
111
  const { content, refusal } = choices[0].message;
112
112
  if (refusal) {
@@ -1,8 +1,10 @@
1
1
  export * from './api/index.js';
2
2
  export * from './auto-sidebar/index.js';
3
+ export * from './auto-toc/index.js';
3
4
  export * from './directives/index.js';
4
5
  export * from './global/index.js';
5
6
  export * from './mermaid/index.js';
6
7
  export * from './permission/index.js';
7
8
  export * from './replace/index.js';
8
9
  export * from './shiki/index.js';
10
+ export * from './sitemap/index.js';
@@ -1,8 +1,10 @@
1
1
  export * from './api/index.js';
2
2
  export * from './auto-sidebar/index.js';
3
+ export * from './auto-toc/index.js';
3
4
  export * from './directives/index.js';
4
5
  export * from './global/index.js';
5
6
  export * from './mermaid/index.js';
6
7
  export * from './permission/index.js';
7
8
  export * from './replace/index.js';
8
9
  export * from './shiki/index.js';
10
+ export * from './sitemap/index.js';
@@ -0,0 +1,16 @@
1
+ import type { RspressPlugin } from '@rspress/shared';
2
+ export type ChangeFreq = 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
3
+ export type Priority = '0.0' | '0.1' | '0.2' | '0.3' | '0.4' | '0.5' | '0.6' | '0.7' | '0.8' | '0.9' | '1.0';
4
+ export interface Sitemap {
5
+ loc: string;
6
+ lastmod?: string;
7
+ changefreq?: ChangeFreq;
8
+ priority?: Priority;
9
+ }
10
+ export interface Options {
11
+ domain?: string;
12
+ customMaps?: Record<string, Sitemap>;
13
+ defaultPriority?: Priority;
14
+ defaultChangeFreq?: ChangeFreq;
15
+ }
16
+ export declare function sitemapPlugin(options?: Options): RspressPlugin;
@@ -0,0 +1,51 @@
1
+ // based on https://github.com/jl917/rspress-plugin-sitemap/blob/master/src/index.ts
2
+ import fs from 'node:fs';
3
+ import { dirname } from 'node:path';
4
+ import { logger } from '@rspress/shared/logger';
5
+ const generateNode = (sitemap) => {
6
+ let result = '<url>';
7
+ for (const [tag, value] of Object.entries(sitemap)) {
8
+ result += `<${tag}>${value}</${tag}>`;
9
+ }
10
+ result += '</url>';
11
+ return result;
12
+ };
13
+ const generateXml = (sitemaps) => {
14
+ logger.log(`Generate sitemap.xml for ${sitemaps.length} pages.`);
15
+ return `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${sitemaps.reduce((node, sitemap) => node + generateNode(sitemap), '')}</urlset>`;
16
+ };
17
+ export function sitemapPlugin(options) {
18
+ options = {
19
+ domain: 'https://rspress.dev',
20
+ customMaps: {},
21
+ defaultChangeFreq: 'monthly',
22
+ defaultPriority: '0.5',
23
+ ...options,
24
+ };
25
+ const sitemaps = [];
26
+ const set = new Set();
27
+ return {
28
+ name: 'rspress-plugin-sitemap',
29
+ extendPageData(pageData, isProd) {
30
+ if (!isProd || set.has(pageData.id)) {
31
+ return;
32
+ }
33
+ set.add(pageData.id);
34
+ sitemaps.push({
35
+ loc: `${options.domain}${pageData.routePath}`,
36
+ lastmod: fs.statSync(pageData._filepath).mtime.toISOString(),
37
+ priority: pageData.routePath === '/' ? '1.0' : options.defaultPriority,
38
+ changefreq: options.defaultChangeFreq,
39
+ ...options.customMaps?.[pageData.routePath],
40
+ });
41
+ },
42
+ afterBuild(config, isProd) {
43
+ if (!isProd) {
44
+ return;
45
+ }
46
+ const outputPath = `${config.outDir || 'doc_build'}/sitemap.xml`;
47
+ fs.mkdirSync(dirname(outputPath), { recursive: true });
48
+ fs.writeFileSync(outputPath, generateXml(sitemaps));
49
+ },
50
+ };
51
+ }
@@ -1,3 +1,3 @@
1
1
  import type { Language } from '../../shared/index.js';
2
2
  export declare const useLang: () => Language;
3
- export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "create" | "update" | "toc" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf") => string;
3
+ export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "toc" | "create" | "update" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf") => string;
package/lib/theme.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const Search: () => import("react/jsx-runtime").JSX.Element;
2
+ export * from '@rspress/core/theme';
3
+ export { Search };
package/lib/theme.js ADDED
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useLang } from '@rspress/core/runtime';
3
+ import { Search as OriginalSearch } from '@rspress/core/theme';
4
+ import { Search as AlgoliaSearch, ZH_LOCALES, } from '@rspress/plugin-algolia/runtime';
5
+ import { useMemo } from 'react';
6
+ const Search = process.env.ALGOLIA_APP_ID &&
7
+ process.env.ALGOLIA_API_KEY &&
8
+ process.env.ALGOLIA_INDEX_NAME
9
+ ? () => {
10
+ const lang = useLang();
11
+ const docSearchProps = useMemo(() => ({
12
+ appId: process.env.ALGOLIA_APP_ID,
13
+ apiKey: process.env.ALGOLIA_API_KEY,
14
+ indexName: process.env.ALGOLIA_INDEX_NAME,
15
+ searchParameters: {
16
+ facetFilters: [`lang:${lang}`],
17
+ },
18
+ }), [lang]);
19
+ return (_jsx(AlgoliaSearch, { docSearchProps: docSearchProps, locales: ZH_LOCALES }));
20
+ }
21
+ : OriginalSearch;
22
+ // eslint-disable-next-line import-x/export
23
+ export * from '@rspress/core/theme';
24
+ // eslint-disable-next-line import-x/export
25
+ export { Search };
package/lib/types.d.ts CHANGED
@@ -20,6 +20,8 @@ export interface GlobalCliOptions {
20
20
  outDir?: string;
21
21
  redirect?: 'auto' | 'never' | 'only-default-lang';
22
22
  editRepo?: boolean | string;
23
+ algolia?: boolean;
24
+ siteUrl?: boolean;
23
25
  }
24
26
  export interface TranslateOptions {
25
27
  systemPrompt?: string;
@@ -28,6 +30,11 @@ export interface TranslateOptions {
28
30
  export interface LintOptions {
29
31
  cspellOptions?: Partial<Options>;
30
32
  }
33
+ export interface AlgoliaOptions {
34
+ appId: string;
35
+ apiKey: string;
36
+ indexName: string;
37
+ }
31
38
  declare module '@rspress/shared' {
32
39
  interface UserConfig {
33
40
  prefix?: string;
@@ -43,6 +50,8 @@ declare module '@rspress/shared' {
43
50
  translate?: TranslateOptions;
44
51
  editRepoBaseUrl?: string;
45
52
  lint?: LintOptions;
53
+ algolia?: AlgoliaOptions;
54
+ siteUrl?: string;
46
55
  }
47
56
  interface SiteData {
48
57
  originalTitle?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.0.0-next.2",
3
+ "version": "1.0.0-next.3",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "git+https://github.com/alauda/doom.git",
@@ -14,6 +14,7 @@
14
14
  "./package.json": "./package.json",
15
15
  "./config": "./lib/config.js",
16
16
  "./runtime": "./lib/runtime/index.js",
17
+ "./theme": "./lib/theme.js",
17
18
  "./types": "./lib/types.js"
18
19
  },
19
20
  "files": [
@@ -41,11 +42,13 @@
41
42
  "@rsbuild/plugin-sass": "^1.3.1",
42
43
  "@rsbuild/plugin-yaml": "^1.0.2",
43
44
  "@rspress/core": "2.0.0-beta.8",
45
+ "@rspress/plugin-algolia": "2.0.0-beta.8",
46
+ "@rspress/plugin-llms": "^2.0.0-beta.8",
44
47
  "@shikijs/transformers": "^3.4.2",
45
48
  "chokidar": "^4.0.3",
46
49
  "cli-progress": "^3.12.0",
47
50
  "clsx": "^2.1.1",
48
- "commander": "^14.0.0",
51
+ "commander": "^13.1.0",
49
52
  "ejs": "^3.1.10",
50
53
  "es-toolkit": "^1.38.0",
51
54
  "eslint": "^9.27.0",
@@ -73,7 +76,7 @@
73
76
  "swagger2openapi": "^7.0.8",
74
77
  "tinyglobby": "^0.2.14",
75
78
  "type-fest": "^4.41.0",
76
- "typescript-eslint": "^8.32.1",
79
+ "typescript-eslint": "^8.33.0",
77
80
  "x-fetch": "^0.2.6",
78
81
  "yaml": "^2.8.0",
79
82
  "yoctocolors": "^2.1.1"