@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 +22 -18
- package/lib/cli/helpers.d.ts +1 -0
- package/lib/cli/helpers.js +1 -1
- package/lib/cli/load-config.js +9 -6
- package/lib/cli/translate.js +2 -1
- package/lib/theme.js +11 -4
- package/lib/types.d.ts +2 -1
- package/package.json +1 -1
- package/styles/global.scss +12 -1
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.
|
|
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
|
-
|
|
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
|
|
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 (
|
|
108
|
-
|
|
112
|
+
if (scope.includes(item._fileKey)) {
|
|
113
|
+
found.add(item);
|
|
109
114
|
}
|
|
110
115
|
if ('items' in item) {
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
132
|
+
const foundSidebarItems = [...found];
|
|
133
|
+
await exportPdf(foundSidebarItems, lang, {
|
|
130
134
|
allOutlines,
|
|
131
|
-
outFile: `${item.name ||
|
|
135
|
+
outFile: `${item.name || (foundSidebarItems.find((it) => it.link?.endsWith('/index')) ?? foundSidebarItems[0]).text}-${lang}.pdf`,
|
|
132
136
|
});
|
|
133
137
|
}
|
|
134
138
|
};
|
package/lib/cli/helpers.d.ts
CHANGED
|
@@ -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}`
|
package/lib/cli/helpers.js
CHANGED
|
@@ -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()) {
|
package/lib/cli/load-config.js
CHANGED
|
@@ -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 {
|
|
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 =
|
|
327
|
-
|
|
328
|
-
|
|
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
|
}
|
package/lib/cli/translate.js
CHANGED
|
@@ -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:
|
|
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 (
|
|
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
|
-
|
|
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
package/package.json
CHANGED
package/styles/global.scss
CHANGED
|
@@ -54,7 +54,7 @@ td {
|
|
|
54
54
|
margin-left: 4px;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
.has-callouts
|
|
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
|
+
}
|