@alauda/doom 1.7.1 → 1.8.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.
package/lib/cli/export.js CHANGED
@@ -10,21 +10,25 @@ import { pathExists, setNodeEnv } from '../utils/index.js';
10
10
  import { generatePdf, } from './export-pdf-core/index.js';
11
11
  import { loadConfig } from './load-config.js';
12
12
  const collectPages = (sidebarItems, base) => {
13
- const pages = [];
13
+ const pages = new Map();
14
14
  for (const item of sidebarItems) {
15
15
  if ('link' in item && item.link) {
16
16
  const link = removeLeadingSlash(item.link);
17
- pages.push({
17
+ pages.set(link, {
18
18
  key: link,
19
19
  path: base + link + '.html?print',
20
20
  title: item.text,
21
21
  });
22
22
  }
23
23
  if ('items' in item) {
24
- pages.push(...collectPages(item.items, base));
24
+ for (const page of collectPages(item.items, base)) {
25
+ if (!pages.has(page.key)) {
26
+ pages.set(page.key, page);
27
+ }
28
+ }
25
29
  }
26
30
  }
27
- return pages;
31
+ return [...pages.values()];
28
32
  };
29
33
  export const exportCommand = new Command('export')
30
34
  .description('Export the documentation as PDF, `apis/**` and `*/apis/**` routes will be ignored automatically')
@@ -99,36 +103,36 @@ export const exportCommand = new Command('export')
99
103
  logger.start(`Exporting ${options ? 'custom' : 'all'} ${lang} language documents with ${pages.length} pages into ${yellow(pdfOptions.outFile)}...`);
100
104
  return generatePdf(pdfOptions);
101
105
  };
102
- const findEntryFactory = (entry) => function findEntry(sidebarItems) {
106
+ const findScopeFactory = (scope) => function findScope(sidebarItems) {
107
+ const found = new Set();
103
108
  for (const item of sidebarItems) {
104
109
  if (!('_fileKey' in item) || !item._fileKey) {
105
110
  continue;
106
111
  }
107
- if (entry.includes(item._fileKey)) {
108
- return item;
112
+ if (scope.includes(item._fileKey)) {
113
+ found.add(item);
109
114
  }
110
115
  if ('items' in item) {
111
- const found = findEntry(item.items);
112
- if (found) {
113
- return found;
116
+ const found_ = findScope(item.items);
117
+ if (found_?.size) {
118
+ found_.forEach((i) => found.add(i));
114
119
  }
115
120
  }
116
121
  }
122
+ return found;
117
123
  };
118
124
  const exportItems = config.export || [];
119
125
  const exportEntries = async (sidebarItems, allOutlines, lang = config.lang) => {
120
126
  for (const item of exportItems) {
121
- // already normalized by `loadConfig`
122
- const entry = item.entry;
123
- const findEntry = findEntryFactory(entry);
124
- const found = findEntry(sidebarItems);
125
- if (!found) {
126
- logger.warn(`Cannot find entry \`${cyan(entry.join(', '))}\` for lang ${lang}, skip exporting`);
127
+ const found = findScopeFactory(item.flattenScope)(sidebarItems);
128
+ if (!found?.size) {
129
+ logger.warn(`Cannot find matched scope \`${cyan(item.scope.join(', '))}\` for lang ${lang}, skip exporting`);
127
130
  continue;
128
131
  }
129
- await exportPdf([found], lang, {
132
+ const foundSidebarItems = [...found];
133
+ await exportPdf(foundSidebarItems, lang, {
130
134
  allOutlines,
131
- outFile: `${item.name || found.text}-${lang}.pdf`,
135
+ outFile: `${item.name || (foundSidebarItems.find((it) => it.link?.endsWith('/index')) ?? foundSidebarItems[0]).text}-${lang}.pdf`,
132
136
  });
133
137
  }
134
138
  };
@@ -1,5 +1,6 @@
1
1
  export declare const parseBoolean: (value?: string) => boolean;
2
2
  export declare const parseBooleanOrString: (value?: string) => string | boolean;
3
+ export declare const isDoc: (filename: string) => boolean;
3
4
  export declare const getMatchedDocFilePaths: (matched: string[]) => Promise<(string | string[])[]>;
4
5
  /**
5
6
  * Support custom id like `#hello world {#custom-id}`
@@ -7,7 +7,7 @@ export const parseBoolean = (value) => value === undefined || !FALSY_VALUES.has(
7
7
  export const parseBooleanOrString = (value) => value === undefined ||
8
8
  (FALSY_VALUES.has(value) ? false : TRUTHY_VALUES.has(value) || value);
9
9
  const DOC_PATTERN = /\.mdx?$/;
10
- const isDoc = (filename) => DOC_PATTERN.test(filename);
10
+ export const isDoc = (filename) => DOC_PATTERN.test(filename);
11
11
  export const getMatchedDocFilePaths = (matched) => Promise.all(matched.map(async (it) => {
12
12
  const stat = await fs.stat(it);
13
13
  if (stat.isDirectory()) {
@@ -11,14 +11,14 @@ import { pluginLlms } from '@rspress/plugin-llms';
11
11
  import { logger } from '@rspress/shared/logger';
12
12
  import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
13
13
  import { difference } from 'es-toolkit';
14
- import { globSync } from 'tinyglobby';
14
+ import { glob } from 'tinyglobby';
15
15
  import { cyan } from 'yoctocolors';
16
16
  import { attributesPlugin } from '../plugins/attributes/index.js';
17
17
  import { apiPlugin, autoSidebarPlugin, autoTocPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, replacePlugin, sitemapPlugin, } from '../plugins/index.js';
18
18
  import { isExplicitlyUnversioned, UNVERSIONED, } from '../shared/index.js';
19
19
  import { pathExists, pkgResolve, resolveStaticConfig } from '../utils/index.js';
20
20
  import { DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
21
- import { defaultGitHubUrl } from './helpers.js';
21
+ import { defaultGitHubUrl, isDoc } from './helpers.js';
22
22
  const DEFAULT_LOGO = '/logo.svg';
23
23
  const KNOWN_LOCALE_CONFIGS = {
24
24
  en: {
@@ -323,10 +323,13 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
323
323
  lang: commonConfig.lang,
324
324
  root: commonConfig.root,
325
325
  });
326
- mergedConfig.export = config.export?.map((item) => ({
327
- ...item,
328
- entry: globSync(item.entry, { cwd: commonConfig.root }),
329
- }));
326
+ mergedConfig.export =
327
+ config.export &&
328
+ (await Promise.all(config.export.map(async (item) => ({
329
+ ...item,
330
+ scope: Array.isArray(item.scope) ? item.scope : [item.scope],
331
+ flattenScope: (await glob(item.scope, { cwd: commonConfig.root })).filter(isDoc),
332
+ }))));
330
333
  if (base && prefix) {
331
334
  mergedConfig.base = (mergedConfig.prefix = normalizeSlash(prefix)) + base;
332
335
  }
@@ -83,6 +83,7 @@ The text for translation is provided below, within triple quotes:
83
83
  <% } %>
84
84
  `.trim();
85
85
  let openai;
86
+ const openaiModel = process.env.AZURE_OPENAI_MODEL || 'gpt-4.1-mini';
86
87
  const resolveTerms = async (sourceLang, targetLang, sourceContent) => {
87
88
  const parsedTerms = await parseTerms();
88
89
  // Filter terms that exist in source content and have translations for both source and target languages
@@ -244,7 +245,7 @@ export const translate = async ({ source, sourceContent, target, systemPrompt, u
244
245
  content: contentWithPlaceholders,
245
246
  },
246
247
  ],
247
- model: 'gpt-4.1-mini',
248
+ model: openaiModel,
248
249
  temperature: 0.2,
249
250
  });
250
251
  const { content, refusal } = choices[0].message;
package/lib/theme.js CHANGED
@@ -13,7 +13,10 @@ const X = getCustomMDXComponent();
13
13
  const getClosestSidebar_ = (sidebarItems, pathname, exportItem, matched, depth = 0) => {
14
14
  for (const sidebar of sidebarItems) {
15
15
  if ('_fileKey' in sidebar && sidebar._fileKey) {
16
- if (exportItem.entry.includes(sidebar._fileKey)) {
16
+ if (depth === 0) {
17
+ matched = undefined;
18
+ }
19
+ if (exportItem.flattenScope.includes(sidebar._fileKey)) {
17
20
  matched = {
18
21
  sidebar,
19
22
  exportItem,
@@ -26,7 +29,7 @@ const getClosestSidebar_ = (sidebarItems, pathname, exportItem, matched, depth =
26
29
  }
27
30
  }
28
31
  if ('items' in sidebar) {
29
- const found = getClosestSidebar_(sidebar.items, pathname, exportItem, matched);
32
+ const found = getClosestSidebar_(sidebar.items, pathname, exportItem, matched, depth + 1);
30
33
  if (found) {
31
34
  return found;
32
35
  }
@@ -52,13 +55,17 @@ export const Layout = () => {
52
55
  const t = useTranslation();
53
56
  const { pathname } = useLocation();
54
57
  const found = useMemo(() => {
55
- if (!virtual.export?.length) {
58
+ if (!virtual.download || !virtual.export?.length) {
56
59
  return;
57
60
  }
58
61
  if (themeConfig.locales?.length) {
62
+ let found;
59
63
  for (const { lang, sidebar } of themeConfig.locales) {
60
64
  const sidebarItems = sidebar[siteLang === lang ? '/' : `/${lang}`];
61
- return getClosestSidebar(sidebarItems, pathname);
65
+ found ??= getClosestSidebar(sidebarItems, pathname);
66
+ if (found) {
67
+ return found;
68
+ }
62
69
  }
63
70
  }
64
71
  else {
package/lib/types.d.ts CHANGED
@@ -37,7 +37,8 @@ export interface AlgoliaOptions {
37
37
  }
38
38
  export interface ExportItem {
39
39
  name?: string;
40
- entry: string | string[];
40
+ scope: string | string[];
41
+ flattenScope?: string[];
41
42
  onlyInclude?: string[];
42
43
  exclude?: string[];
43
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.7.1",
3
+ "version": "1.8.1",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "git+https://github.com/alauda/doom.git",
@@ -54,7 +54,7 @@ td {
54
54
  margin-left: 4px;
55
55
  }
56
56
 
57
- .has-callouts .rspress-code-content {
57
+ .has-callouts {
58
58
  counter-reset: callouts;
59
59
 
60
60
  .line.callout {
@@ -145,3 +145,14 @@ td {
145
145
  @media print {
146
146
  @include print;
147
147
  }
148
+
149
+ .rp-list-decimal {
150
+ list-style: none;
151
+ counter-reset: section;
152
+ padding-left: 20px;
153
+ }
154
+
155
+ .rp-list-decimal > li:before {
156
+ counter-increment: section;
157
+ content: counters(section, '.') '. ';
158
+ }