@alauda/doom 0.12.1 → 0.13.0
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-pdf-core/generatePdf.d.ts +19 -0
- package/lib/cli/export-pdf-core/generatePdf.js +81 -0
- package/lib/cli/export-pdf-core/index.d.ts +3 -0
- package/lib/cli/export-pdf-core/index.js +3 -0
- package/lib/cli/export-pdf-core/types.d.ts +15 -0
- package/lib/cli/export-pdf-core/types.js +1 -0
- package/lib/cli/export-pdf-core/utils/convertPathToPosix.d.ts +8 -0
- package/lib/cli/export-pdf-core/utils/convertPathToPosix.js +26 -0
- package/lib/cli/export-pdf-core/utils/filterRoute.d.ts +8 -0
- package/lib/cli/export-pdf-core/utils/filterRoute.js +11 -0
- package/lib/cli/export-pdf-core/utils/getUrlLink.d.ts +4 -0
- package/lib/cli/export-pdf-core/utils/getUrlLink.js +7 -0
- package/lib/cli/export-pdf-core/utils/index.d.ts +3 -0
- package/lib/cli/export-pdf-core/utils/index.js +3 -0
- package/lib/cli/export-pdf-core/utils/mergePDF.d.ts +27 -0
- package/lib/cli/export-pdf-core/utils/mergePDF.js +140 -0
- package/lib/cli/export-pdf-core/utils/timeTransformer.d.ts +8 -0
- package/lib/cli/export-pdf-core/utils/timeTransformer.js +22 -0
- package/lib/cli/export.d.ts +0 -2
- package/lib/cli/export.js +87 -19
- package/lib/cli/html-export-pdf/core/index.d.ts +3 -0
- package/lib/cli/html-export-pdf/core/index.js +3 -0
- package/lib/cli/html-export-pdf/core/outline.d.ts +47 -0
- package/lib/cli/html-export-pdf/core/outline.js +216 -0
- package/lib/cli/html-export-pdf/core/postprocesser.d.ts +14 -0
- package/lib/cli/html-export-pdf/core/postprocesser.js +38 -0
- package/lib/cli/html-export-pdf/core/printer.d.ts +61 -0
- package/lib/cli/html-export-pdf/core/printer.js +235 -0
- package/lib/cli/html-export-pdf/index.d.ts +2 -0
- package/lib/cli/html-export-pdf/index.js +2 -0
- package/lib/cli/html-export-pdf/utils/cliProgress.d.ts +13 -0
- package/lib/cli/html-export-pdf/utils/cliProgress.js +80 -0
- package/lib/cli/html-export-pdf/utils/fs.d.ts +5 -0
- package/lib/cli/html-export-pdf/utils/fs.js +18 -0
- package/lib/cli/html-export-pdf/utils/getAbsFileName.d.ts +1 -0
- package/lib/cli/html-export-pdf/utils/getAbsFileName.js +4 -0
- package/lib/cli/html-export-pdf/utils/getDirname.d.ts +1 -0
- package/lib/cli/html-export-pdf/utils/getDirname.js +5 -0
- package/lib/cli/html-export-pdf/utils/index.d.ts +7 -0
- package/lib/cli/html-export-pdf/utils/index.js +7 -0
- package/lib/cli/html-export-pdf/utils/isValidUrl.d.ts +1 -0
- package/lib/cli/html-export-pdf/utils/isValidUrl.js +3 -0
- package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.d.ts +2 -0
- package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.js +6 -0
- package/lib/cli/html-export-pdf/utils/replaceExt.d.ts +1 -0
- package/lib/cli/html-export-pdf/utils/replaceExt.js +19 -0
- package/lib/cli/index.js +8 -12
- package/lib/cli/load-config.js +2 -5
- package/lib/cli/merge-pdfs/formatDate.d.ts +1 -0
- package/lib/cli/merge-pdfs/formatDate.js +23 -0
- package/lib/cli/merge-pdfs/index.d.ts +8 -0
- package/lib/cli/merge-pdfs/index.js +62 -0
- package/lib/global/PrintStyle/index.d.ts +2 -0
- package/lib/global/PrintStyle/index.js +13 -0
- package/lib/plugins/auto-sidebar/index.d.ts +3 -2
- package/lib/plugins/auto-sidebar/index.js +33 -34
- package/lib/plugins/index.d.ts +3 -0
- package/lib/plugins/index.js +3 -0
- package/lib/runtime/components/ExternalSiteLink.js +9 -6
- package/lib/runtime/components/K8sCrd.js +4 -3
- package/lib/runtime/hooks/index.d.ts +1 -0
- package/lib/runtime/hooks/index.js +1 -0
- package/lib/runtime/hooks/useIsPrint.d.ts +3 -0
- package/lib/runtime/hooks/useIsPrint.js +31 -0
- package/lib/runtime/hooks/useTranslation.d.ts +1 -1
- package/lib/utils/helpers.d.ts +2 -0
- package/lib/utils/helpers.js +4 -0
- package/lib/utils/types.d.ts +3 -1
- package/package.json +11 -1
- package/styles/global.scss +30 -0
- package/styles/shiki.css +3 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { dirname } from 'node:path';
|
|
2
|
+
import { existsSync, promises as fs } from 'node:fs';
|
|
3
|
+
/**
|
|
4
|
+
* Write file safely
|
|
5
|
+
*/
|
|
6
|
+
export async function writeFileSafe(path, data = '') {
|
|
7
|
+
const directory = dirname(path);
|
|
8
|
+
if (!existsSync(directory)) {
|
|
9
|
+
await fs.mkdir(directory, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
await fs.writeFile(path, data);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAbsFileName(metaURL: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDirname(metaURL: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValidUrl(url: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function replaceExt(npath: string, ext: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
function startsWithSingleDot(filePath) {
|
|
3
|
+
const first2chars = filePath.slice(0, 2);
|
|
4
|
+
return first2chars === `.${path.sep}` || first2chars === './';
|
|
5
|
+
}
|
|
6
|
+
export function replaceExt(npath, ext) {
|
|
7
|
+
if (typeof npath !== 'string' || npath.length === 0) {
|
|
8
|
+
return npath;
|
|
9
|
+
}
|
|
10
|
+
const nFileName = path.basename(npath, path.extname(npath)) + ext;
|
|
11
|
+
const nFilepath = path.join(path.dirname(npath), nFileName);
|
|
12
|
+
// Because `path.join` removes the head './' from the given path.
|
|
13
|
+
// This removal can cause a problem when passing the result to `require` or
|
|
14
|
+
// `import`.
|
|
15
|
+
if (startsWithSingleDot(npath)) {
|
|
16
|
+
return `.${path.sep}${nFilepath}`;
|
|
17
|
+
}
|
|
18
|
+
return nFilepath;
|
|
19
|
+
}
|
package/lib/cli/index.js
CHANGED
|
@@ -13,11 +13,10 @@ import { CWD, DEFAULT_CONFIGS, I18N_FILE, SITES_FILE } from './constants.js';
|
|
|
13
13
|
import { loadConfig } from './load-config.js';
|
|
14
14
|
import { newCommand } from './new.js';
|
|
15
15
|
import { translateCommand } from './translate.js';
|
|
16
|
+
import { exportCommand } from './export.js';
|
|
17
|
+
import { setNodeEnv, } from '../utils/index.js';
|
|
16
18
|
const META_FILE = '_meta.json';
|
|
17
19
|
const CONFIG_FILES = [...DEFAULT_CONFIGS, I18N_FILE, SITES_FILE];
|
|
18
|
-
const setNodeEnv = (env) => {
|
|
19
|
-
process.env.NODE_ENV = env;
|
|
20
|
-
};
|
|
21
20
|
const cjsRequire = module.createRequire(import.meta.url);
|
|
22
21
|
const pkg = cjsRequire('../../package.json');
|
|
23
22
|
program
|
|
@@ -35,8 +34,8 @@ program
|
|
|
35
34
|
.command('dev', { isDefault: true })
|
|
36
35
|
.description('Start the development server')
|
|
37
36
|
.argument('[root]', 'Root directory of the documentation')
|
|
38
|
-
.option('--host [host]', '
|
|
39
|
-
.option('--port [port]', '
|
|
37
|
+
.option('-H, --host [host]', 'Dev server host name')
|
|
38
|
+
.option('-P, --port [port]', 'Dev server port number')
|
|
40
39
|
.action(async function (root) {
|
|
41
40
|
setNodeEnv('development');
|
|
42
41
|
let devServer;
|
|
@@ -124,20 +123,17 @@ program
|
|
|
124
123
|
.alias('serve')
|
|
125
124
|
.description('Preview the built documentation')
|
|
126
125
|
.argument('[root]', 'Root directory of the documentation')
|
|
127
|
-
.option('--host [host]', '
|
|
128
|
-
.option('--port [port]', '
|
|
126
|
+
.option('-H, --host [host]', 'Serve host name')
|
|
127
|
+
.option('-P, --port [port]', 'Serve port number', '4173')
|
|
129
128
|
.action(async function (root) {
|
|
130
129
|
setNodeEnv('production');
|
|
131
130
|
const { port, host, ...globalOptions } = this.optsWithGlobals();
|
|
132
131
|
const { config } = await loadConfig(root, globalOptions);
|
|
133
|
-
await serve({
|
|
134
|
-
config,
|
|
135
|
-
host,
|
|
136
|
-
port,
|
|
137
|
-
});
|
|
132
|
+
await serve({ config, host, port });
|
|
138
133
|
});
|
|
139
134
|
program.addCommand(newCommand);
|
|
140
135
|
program.addCommand(translateCommand);
|
|
136
|
+
program.addCommand(exportCommand);
|
|
141
137
|
program.parseAsync().catch((err) => {
|
|
142
138
|
if (err instanceof Error && err.name === 'ExitPromptError') {
|
|
143
139
|
return;
|
package/lib/cli/load-config.js
CHANGED
|
@@ -5,10 +5,7 @@ import { addLeadingSlash, addTrailingSlash, normalizeSlash, removeLeadingSlash,
|
|
|
5
5
|
import { logger } from '@rspress/shared/logger';
|
|
6
6
|
import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
|
|
7
7
|
import rehypeRaw from 'rehype-raw';
|
|
8
|
-
import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, shikiPlugin, } from '../plugins/index.js';
|
|
9
|
-
import { mermaidPlugin } from '../plugins/mermaid/index.js';
|
|
10
|
-
import { permissionPlugin } from '../plugins/permission/index.js';
|
|
11
|
-
import { replacePlugin } from '../plugins/replace/index.js';
|
|
8
|
+
import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, replacePlugin, shikiPlugin, } from '../plugins/index.js';
|
|
12
9
|
import { normalizeVersion } from '../shared/index.js';
|
|
13
10
|
import { pkgResolve, resolveStaticConfig, } from '../utils/index.js';
|
|
14
11
|
import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
|
|
@@ -89,7 +86,7 @@ const getCommonConfig = (config, cliRoot, configFilePath, version, ignore, force
|
|
|
89
86
|
releaseNotes: config.releaseNotes,
|
|
90
87
|
}),
|
|
91
88
|
shikiPlugin({
|
|
92
|
-
langs: ['dockerfile', 'html', 'go', 'jsonc', 'mermaid'],
|
|
89
|
+
langs: ['dockerfile', 'dotenv', 'html', 'go', 'jsonc', 'mermaid'],
|
|
93
90
|
transformers: [
|
|
94
91
|
// builtin transformers
|
|
95
92
|
transformerMetaHighlight(),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatDate(date: Date): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function formatDate(date) {
|
|
2
|
+
const year = date.getFullYear();
|
|
3
|
+
const month = date.getMonth() + 1;
|
|
4
|
+
const day = date.getDate();
|
|
5
|
+
const hour = date.getHours();
|
|
6
|
+
const minute = date.getMinutes();
|
|
7
|
+
const second = date.getSeconds();
|
|
8
|
+
const paddedMonth = `00${month}`.slice(-2);
|
|
9
|
+
const paddedDay = `00${day}`.slice(-2);
|
|
10
|
+
const paddedHour = `00${hour}`.slice(-2);
|
|
11
|
+
const paddedMinute = `00${minute}`.slice(-2);
|
|
12
|
+
const paddedSecond = `00${second}`.slice(-2);
|
|
13
|
+
const str = `D:${year}${paddedMonth}${paddedDay}${paddedHour}${paddedMinute}${paddedSecond}`;
|
|
14
|
+
let offset = date.getTimezoneOffset();
|
|
15
|
+
const rel = offset === 0 ? 'Z' : offset > 0 ? '-' : '+';
|
|
16
|
+
offset = Math.abs(offset);
|
|
17
|
+
const hoursOffset = Math.floor(offset / 60);
|
|
18
|
+
const minutesOffset = offset - hoursOffset * 60;
|
|
19
|
+
const paddedHoursOffset = `00${hoursOffset}`.slice(-2);
|
|
20
|
+
const paddedMinutesOffset = `00${minutesOffset}`.slice(-2);
|
|
21
|
+
// D:YYYYMMDDHHmmSSOHH'mm'
|
|
22
|
+
return `${str}${rel}${paddedHoursOffset}'${paddedMinutesOffset}'`;
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see https://www.uuidgenerator.net/version4
|
|
3
|
+
* UUID v4
|
|
4
|
+
*/
|
|
5
|
+
export declare const MERGE_PDF_NAME = "66699f18-ad5a-43c2-a96e-97bddaef0e6b.pdf";
|
|
6
|
+
export declare const MOUNT_DIR: string;
|
|
7
|
+
export declare function mergePDFs(entries: string[]): Promise<Uint8Array<ArrayBufferLike>>;
|
|
8
|
+
export default mergePDFs;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import x from './pyodide/pyodide.js';
|
|
5
|
+
import { yellowBright } from 'yoctocolors';
|
|
6
|
+
import { formatDate } from './formatDate.js';
|
|
7
|
+
/**
|
|
8
|
+
* @see https://www.uuidgenerator.net/version4
|
|
9
|
+
* UUID v4
|
|
10
|
+
*/
|
|
11
|
+
export const MERGE_PDF_NAME = '66699f18-ad5a-43c2-a96e-97bddaef0e6b.pdf';
|
|
12
|
+
export const MOUNT_DIR = '/' + '991e729a-8f2e-472a-8402-c26bb03b5ea3';
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
export async function mergePDFs(entries) {
|
|
15
|
+
if (entries.length < 2) {
|
|
16
|
+
process.stdout.write(yellowBright('At least two PDF files.\n'));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
const pyodide = await x.loadPyodide({
|
|
20
|
+
indexURL: resolve(__dirname, 'pyodide'),
|
|
21
|
+
});
|
|
22
|
+
await pyodide.loadPackage('micropip');
|
|
23
|
+
const micropip = pyodide.pyimport('micropip');
|
|
24
|
+
pyodide.FS.mkdirTree(MOUNT_DIR);
|
|
25
|
+
pyodide.FS.mount(
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
27
|
+
pyodide.FS.filesystems.NODEFS, { root: __dirname }, MOUNT_DIR);
|
|
28
|
+
/**
|
|
29
|
+
* @see https://github.com/pyodide/pyodide/issues/3246#issuecomment-1312210155
|
|
30
|
+
* You need to prefix the path with emfs: or it will be treated as a url
|
|
31
|
+
*/
|
|
32
|
+
await micropip.install(`emfs:${MOUNT_DIR}/pyodide/pypdf-3.8.1-py3-none-any.whl`);
|
|
33
|
+
const tempFileNameArr = [];
|
|
34
|
+
entries.forEach((filePath) => {
|
|
35
|
+
const tempFileName = `/${filePath.split('/').join('-')}`;
|
|
36
|
+
tempFileNameArr.push(tempFileName);
|
|
37
|
+
pyodide.FS.writeFile(tempFileName, readFileSync(filePath));
|
|
38
|
+
});
|
|
39
|
+
const curDate = formatDate(new Date());
|
|
40
|
+
await pyodide.runPythonAsync(`
|
|
41
|
+
from pypdf import PdfWriter
|
|
42
|
+
from json import loads
|
|
43
|
+
|
|
44
|
+
writer = PdfWriter()
|
|
45
|
+
writer.add_metadata(
|
|
46
|
+
{
|
|
47
|
+
"/CreationDate": "${curDate}",
|
|
48
|
+
"/ModDate": "${curDate}",
|
|
49
|
+
"/Creator": "doom",
|
|
50
|
+
"/Producer": "pypdf - doom",
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
for path in loads('${JSON.stringify(tempFileNameArr)}'):
|
|
55
|
+
writer.append(path)
|
|
56
|
+
|
|
57
|
+
writer.write("/${MERGE_PDF_NAME}")
|
|
58
|
+
writer.close()
|
|
59
|
+
`);
|
|
60
|
+
return pyodide.FS.readFile(`/${MERGE_PDF_NAME}`);
|
|
61
|
+
}
|
|
62
|
+
export default mergePDFs;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useIsPrintQuery } from '@alauda/doom/runtime';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
export const PrintStyle = () => {
|
|
4
|
+
const isPrint = useIsPrintQuery();
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (typeof document === 'undefined') {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const doc = document.documentElement;
|
|
10
|
+
doc.classList[isPrint ? 'add' : 'remove']('print');
|
|
11
|
+
}, [isPrint]);
|
|
12
|
+
};
|
|
13
|
+
export default PrintStyle;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type RspressPlugin } from '@rspress/core';
|
|
1
|
+
import { type RspressPlugin, type UserConfig } from '@rspress/core';
|
|
2
2
|
export interface AutoSidebarPluginOptions {
|
|
3
3
|
excludeRoutes?: string[];
|
|
4
4
|
collapsed?: boolean;
|
|
5
5
|
}
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const autoSidebar: (config: UserConfig, { excludeRoutes, collapsed }: AutoSidebarPluginOptions) => Promise<UserConfig<import("@rspress/shared").DefaultThemeConfig>>;
|
|
7
|
+
export declare const autoSidebarPlugin: (options?: AutoSidebarPluginOptions) => RspressPlugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addTrailingSlash } from '@rspress/core';
|
|
1
|
+
import { addTrailingSlash, } from '@rspress/core';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { combineWalkResult } from './utils.js';
|
|
4
4
|
import { walk } from './walk.js';
|
|
@@ -154,43 +154,42 @@ function processLocales(langs, versions, root, defaultLang, defaultVersion, exte
|
|
|
154
154
|
}));
|
|
155
155
|
}
|
|
156
156
|
const defaultExtensions = ['.mdx', '.md', '.tsx', '.jsx', '.ts', '.js'];
|
|
157
|
-
export const
|
|
157
|
+
export const autoSidebar = async (config, { excludeRoutes, collapsed }) => {
|
|
158
|
+
config.themeConfig = config.themeConfig || {};
|
|
159
|
+
config.themeConfig.locales =
|
|
160
|
+
config.themeConfig.locales || config.locales || [];
|
|
161
|
+
const root = config.root;
|
|
162
|
+
const langs = config.themeConfig.locales.map((locale) => locale.lang);
|
|
163
|
+
const hasLocales = langs.length > 0;
|
|
164
|
+
const versions = config.multiVersion?.versions || [];
|
|
165
|
+
const defaultLang = config.lang || '';
|
|
166
|
+
const { default: defaultVersion = '' } = config.multiVersion || {};
|
|
167
|
+
const { extensions = defaultExtensions } = config.route || {};
|
|
168
|
+
if (hasLocales) {
|
|
169
|
+
const metaInfo = await processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, excludeRoutes, collapsed);
|
|
170
|
+
config.themeConfig.locales = config.themeConfig.locales.map((item, index) => ({
|
|
171
|
+
...item,
|
|
172
|
+
...metaInfo[index],
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const walks = versions.length
|
|
177
|
+
? await Promise.all(versions.map((version) => {
|
|
178
|
+
const routePrefix = addTrailingSlash(version === defaultVersion ? '' : `/${version}`);
|
|
179
|
+
return walk(path.join(root, version), routePrefix, config.root, extensions, excludeRoutes, collapsed);
|
|
180
|
+
}))
|
|
181
|
+
: [await walk(root, '/', root, extensions, excludeRoutes, collapsed)];
|
|
182
|
+
const combined = combineWalkResult(walks, versions);
|
|
183
|
+
config.themeConfig = { ...config.themeConfig, ...combined };
|
|
184
|
+
}
|
|
185
|
+
return config;
|
|
186
|
+
};
|
|
187
|
+
export const autoSidebarPlugin = (options = {}) => {
|
|
158
188
|
return {
|
|
159
189
|
name: 'doom-auto-sidebar',
|
|
160
190
|
async config(config, utils) {
|
|
161
191
|
utils.removePlugin('auto-nav-sidebar');
|
|
162
|
-
|
|
163
|
-
config.themeConfig.locales =
|
|
164
|
-
config.themeConfig.locales || config.locales || [];
|
|
165
|
-
const root = config.root;
|
|
166
|
-
const langs = config.themeConfig.locales.map((locale) => locale.lang);
|
|
167
|
-
const hasLocales = langs.length > 0;
|
|
168
|
-
const hasLang = Boolean(config.lang);
|
|
169
|
-
const versions = config.multiVersion?.versions || [];
|
|
170
|
-
const defaultLang = config.lang || '';
|
|
171
|
-
const { default: defaultVersion = '' } = config.multiVersion || {};
|
|
172
|
-
const { extensions = defaultExtensions } = config.route || {};
|
|
173
|
-
if (hasLocales) {
|
|
174
|
-
const metaInfo = await processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, excludeRoutes, collapsed);
|
|
175
|
-
config.themeConfig.locales = config.themeConfig.locales.map((item, index) => ({
|
|
176
|
-
...item,
|
|
177
|
-
...metaInfo[index],
|
|
178
|
-
}));
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
if (hasLang) {
|
|
182
|
-
return config;
|
|
183
|
-
}
|
|
184
|
-
const walks = versions.length
|
|
185
|
-
? await Promise.all(versions.map((version) => {
|
|
186
|
-
const routePrefix = addTrailingSlash(version === defaultVersion ? '' : `/${version}`);
|
|
187
|
-
return walk(path.join(root, version), routePrefix, config.root, extensions, excludeRoutes, collapsed);
|
|
188
|
-
}))
|
|
189
|
-
: [await walk(root, '/', root, extensions, excludeRoutes, collapsed)];
|
|
190
|
-
const combined = combineWalkResult(walks, versions);
|
|
191
|
-
config.themeConfig = { ...config.themeConfig, ...combined };
|
|
192
|
-
}
|
|
193
|
-
return config;
|
|
192
|
+
return autoSidebar(config, options);
|
|
194
193
|
},
|
|
195
194
|
};
|
|
196
195
|
};
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -2,4 +2,7 @@ export * from './api/index.js';
|
|
|
2
2
|
export * from './auto-sidebar/index.js';
|
|
3
3
|
export * from './directives/index.js';
|
|
4
4
|
export * from './global/index.js';
|
|
5
|
+
export * from './mermaid/index.js';
|
|
6
|
+
export * from './permission/index.js';
|
|
7
|
+
export * from './replace/index.js';
|
|
5
8
|
export * from './shiki/index.js';
|
package/lib/plugins/index.js
CHANGED
|
@@ -2,4 +2,7 @@ export * from './api/index.js';
|
|
|
2
2
|
export * from './auto-sidebar/index.js';
|
|
3
3
|
export * from './directives/index.js';
|
|
4
4
|
export * from './global/index.js';
|
|
5
|
+
export * from './mermaid/index.js';
|
|
6
|
+
export * from './permission/index.js';
|
|
7
|
+
export * from './replace/index.js';
|
|
5
8
|
export * from './shiki/index.js';
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useLang } from '@rspress/core/runtime';
|
|
2
|
+
import { NoSSR, useLang } from '@rspress/core/runtime';
|
|
3
3
|
import { addTrailingSlash, isExternalUrl, removeLeadingSlash, } from '@rspress/shared';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
import { Directive } from './Directive.js';
|
|
7
7
|
import virtual from 'doom-@global-virtual';
|
|
8
8
|
import classes from '../../../styles/link.module.scss';
|
|
9
|
+
import { useIsPrint } from '../hooks/index.js';
|
|
9
10
|
export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
|
|
11
|
+
const isPrint = useIsPrint();
|
|
10
12
|
const site = useMemo(() => virtual.sites?.find((s) => s.name === name), []);
|
|
11
13
|
const lang = useLang();
|
|
12
14
|
if (!site) {
|
|
@@ -15,10 +17,11 @@ export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
|
|
|
15
17
|
if (isExternalUrl(href)) {
|
|
16
18
|
return _jsxs(Directive, { type: "danger", children: ["Invalid href `", href, "` found"] });
|
|
17
19
|
}
|
|
18
|
-
return (_jsx("a", { href: (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
return (_jsx(NoSSR, { children: _jsx("a", { href: (isPrint ? 'https://docs.alauda.io' : '') +
|
|
21
|
+
(virtual.version
|
|
22
|
+
? addTrailingSlash(site.base + site.version)
|
|
23
|
+
: site.base) +
|
|
24
|
+
(lang ? `${lang}/` : '') +
|
|
25
|
+
removeLeadingSlash(href), target: "_blank", rel: "noopener noreferrer", className: clsx(classes.link, 'cursor-pointer', className), ...props }) }));
|
|
23
26
|
};
|
|
24
27
|
export default ExternalSiteLink;
|
|
@@ -4,7 +4,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
4
4
|
*/
|
|
5
5
|
import { Badge, Button, getCustomMDXComponent } from '@rspress/core/theme';
|
|
6
6
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
7
|
-
import { useTranslation } from '../hooks/index.js';
|
|
7
|
+
import { useIsPrint, useTranslation } from '../hooks/index.js';
|
|
8
8
|
import { Directive } from './Directive.js';
|
|
9
9
|
import { Markdown } from './_Markdown.js';
|
|
10
10
|
import crdsMap from 'doom-@api-crdsMap';
|
|
@@ -43,12 +43,13 @@ export const K8sCrdSchemaPart = ({ name, parent, schema: property, expandAll, })
|
|
|
43
43
|
const SKIPPED_PROPERTIES = ['apiVersion', 'kind', 'metadata'];
|
|
44
44
|
export const K8sCrdSchema = ({ schema, version, }) => {
|
|
45
45
|
const { description, properties } = schema;
|
|
46
|
+
const isPrint = useIsPrint();
|
|
46
47
|
const t = useTranslation();
|
|
47
|
-
const [expandAll, setExpandAll] = useState(
|
|
48
|
+
const [expandAll, setExpandAll] = useState(isPrint);
|
|
48
49
|
const toggleExpandAll = useCallback(() => {
|
|
49
50
|
setExpandAll((all) => !all);
|
|
50
51
|
}, []);
|
|
51
|
-
return (_jsxs(_Fragment, { children: [_jsx(Markdown, { children: description }), _jsxs("div", { className: "flex items-center", children: [_jsxs("span", { children: [_jsx("code", { children: version }), _jsx(Badge, { children: "version" })] }), properties != null && (_jsx(Button, { className: "ml-auto doom-btn", type: "button", text: _jsxs("span", { onClick: toggleExpandAll, children: [expandAll ? '-' : '+', ' ', t(expandAll ? 'collapse_all' : 'expand_all')] }), size: "medium", theme: "alt" }))] }), properties == null ? (_jsx(Directive, { type: "warning", children: t('crd_no_schema') })) : (_jsx("div", { className: "doom-collapse-group", children: Object.entries(properties).map(([name, subSchema]) => SKIPPED_PROPERTIES.includes(name) || (_jsx(K8sCrdSchemaPart, { name: name, parent: schema, schema: subSchema, expandAll: expandAll }, name))) }))] }));
|
|
52
|
+
return (_jsxs(_Fragment, { children: [_jsx(Markdown, { children: description }), _jsxs("div", { className: "flex items-center", children: [_jsxs("span", { children: [_jsx("code", { children: version }), _jsx(Badge, { children: "version" })] }), !isPrint && properties != null && (_jsx(Button, { className: "ml-auto doom-btn", type: "button", text: _jsxs("span", { onClick: toggleExpandAll, children: [expandAll ? '-' : '+', ' ', t(expandAll ? 'collapse_all' : 'expand_all')] }), size: "medium", theme: "alt" }))] }), properties == null ? (_jsx(Directive, { type: "warning", children: t('crd_no_schema') })) : (_jsx("div", { className: "doom-collapse-group", children: Object.entries(properties).map(([name, subSchema]) => SKIPPED_PROPERTIES.includes(name) || (_jsx(K8sCrdSchemaPart, { name: name, parent: schema, schema: subSchema, expandAll: expandAll }, name))) }))] }));
|
|
52
53
|
};
|
|
53
54
|
export const K8sCrd = ({ name, crdPath }) => {
|
|
54
55
|
const [X] = useState(getCustomMDXComponent);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo, useCallback } from 'react';
|
|
2
|
+
import { useLocation } from 'react-router';
|
|
3
|
+
export function useIsPrintQuery() {
|
|
4
|
+
const { search } = useLocation();
|
|
5
|
+
const searchParams = useMemo(() => new URLSearchParams(search), [search]);
|
|
6
|
+
const isPrint = searchParams.get('print') === 'true';
|
|
7
|
+
return isPrint;
|
|
8
|
+
}
|
|
9
|
+
const getPrintMediaQuery = () => {
|
|
10
|
+
if (typeof document === 'undefined') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
return matchMedia('print');
|
|
14
|
+
};
|
|
15
|
+
export function useIsPrintMedia() {
|
|
16
|
+
const [printMediaQuery] = useState(getPrintMediaQuery);
|
|
17
|
+
const [isPrint, changeIsPrint] = useState(!!printMediaQuery?.matches);
|
|
18
|
+
const onChange = useCallback((mqList) => {
|
|
19
|
+
changeIsPrint(!!mqList.matches);
|
|
20
|
+
}, []);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
printMediaQuery?.addEventListener('change', onChange);
|
|
23
|
+
return () => printMediaQuery?.removeEventListener('change', onChange);
|
|
24
|
+
}, [printMediaQuery]);
|
|
25
|
+
return isPrint;
|
|
26
|
+
}
|
|
27
|
+
export function useIsPrint() {
|
|
28
|
+
const isPrintQuery = useIsPrintQuery();
|
|
29
|
+
const isPrintMedia = useIsPrintMedia();
|
|
30
|
+
return isPrintQuery || isPrintMedia;
|
|
31
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useTranslation: () => (key: "function" | "delete" | "create" | "update" | "
|
|
1
|
+
export declare const useTranslation: () => (key: "function" | "delete" | "create" | "update" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action") => string;
|
package/lib/utils/helpers.d.ts
CHANGED
|
@@ -3,3 +3,5 @@ export declare const baseResolve: (...paths: string[]) => string;
|
|
|
3
3
|
export declare const pkgResolve: (...paths: string[]) => string;
|
|
4
4
|
export declare const resolveStaticConfig: <T = unknown>(filepath: string) => Promise<T>;
|
|
5
5
|
export declare function generateRuntimeModule<T, R = T>(patterns: string[], kind: string, root: string, cwd: string, isProd: boolean, mapper?: (input: T) => R | Promise<R>): Promise<StringMapper>;
|
|
6
|
+
export declare const setNodeEnv: (env: "development" | "production") => void;
|
|
7
|
+
export declare const removeBothEndsSlashes: (str: string) => string;
|
package/lib/utils/helpers.js
CHANGED
|
@@ -35,3 +35,7 @@ export async function generateRuntimeModule(patterns, kind, root, cwd, isProd, m
|
|
|
35
35
|
`\nexport default {${files.map((file, index) => `'${path.relative(root, file)}':_${index}`).join(',')}}`;
|
|
36
36
|
return runtimeModules;
|
|
37
37
|
}
|
|
38
|
+
export const setNodeEnv = (env) => {
|
|
39
|
+
process.env.NODE_ENV = env;
|
|
40
|
+
};
|
|
41
|
+
export const removeBothEndsSlashes = (str) => str.replace(/^\/|\/$/g, '');
|
package/lib/utils/types.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { UserConfig } from '@rspress/core';
|
|
1
|
+
import type { serve, UserConfig } from '@rspress/core';
|
|
2
2
|
import type { ApiPluginOptions } from '../plugins/api/types.js';
|
|
3
3
|
import type { AutoSidebarPluginOptions } from '../plugins/index.js';
|
|
4
4
|
import type { PermissionPluginOptions } from '../plugins/permission/types.js';
|
|
5
5
|
import type { ReferenceItem, ReleaseNotesOptions } from '../plugins/replace/types.js';
|
|
6
6
|
import type { DoomSite } from '../shared/index.js';
|
|
7
|
+
export type BaseServeOptions = Parameters<typeof serve>[0];
|
|
8
|
+
export type ServeOptions = Omit<BaseServeOptions, 'config'>;
|
|
7
9
|
export interface GlobalCliOptions {
|
|
8
10
|
config?: string;
|
|
9
11
|
prefix?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -29,31 +29,39 @@
|
|
|
29
29
|
"clean": "tsc -b src --clean",
|
|
30
30
|
"dev": "yarn swc-node --watch-path src/cli --watch-path src/plugins src/cli/index.ts",
|
|
31
31
|
"doom": "yarn swc-node src/cli/index.ts",
|
|
32
|
+
"export": "yarn doom export",
|
|
32
33
|
"fixture": "yarn dev fixture-docs",
|
|
33
34
|
"lint": "run-p 'lint:*'",
|
|
34
35
|
"lint:es": "eslint .",
|
|
35
36
|
"lint:tsc": "tsc -b",
|
|
36
37
|
"prepare": "simple-git-hooks && patch-package",
|
|
37
38
|
"prepublishOnly": "yarn build",
|
|
39
|
+
"serve": "yarn doom serve",
|
|
38
40
|
"swc-node": "node --enable-source-maps --import @swc-node/register/esm-register",
|
|
39
41
|
"translate": "yarn doom translate fixture-docs"
|
|
40
42
|
},
|
|
41
43
|
"dependencies": {
|
|
42
44
|
"@inquirer/prompts": "^7.3.2",
|
|
43
45
|
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
|
|
46
|
+
"@playwright/browser-chromium": "^1.50.1",
|
|
44
47
|
"@rspress/core": "1.42.0",
|
|
45
48
|
"@shikijs/transformers": "^3.0.0",
|
|
46
49
|
"chokidar": "^4.0.3",
|
|
50
|
+
"cli-progress": "^3.12.0",
|
|
47
51
|
"clsx": "^2.1.1",
|
|
48
52
|
"commander": "^13.1.0",
|
|
49
53
|
"ejs": "^3.1.10",
|
|
50
54
|
"es-toolkit": "^1.32.0",
|
|
55
|
+
"fs-extra": "^11.3.0",
|
|
51
56
|
"html-tag-names": "^2.1.0",
|
|
52
57
|
"mermaid": "^11.4.1",
|
|
53
58
|
"openai": "^5.0.0-alpha.0",
|
|
54
59
|
"openapi-types": "^12.1.3",
|
|
55
60
|
"p-ratelimit": "^1.0.1",
|
|
61
|
+
"pdf-lib": "^1.17.1",
|
|
62
|
+
"pdf-merger-js": "^5.1.2",
|
|
56
63
|
"picomatch": "^4.0.2",
|
|
64
|
+
"playwright": "^1.50.1",
|
|
57
65
|
"react-markdown": "^8.0.7",
|
|
58
66
|
"rehype-raw": "^6.1.1",
|
|
59
67
|
"remark-directive": "^2.0.1",
|
|
@@ -71,7 +79,9 @@
|
|
|
71
79
|
"@eslint/js": "^9.21.0",
|
|
72
80
|
"@swc-node/register": "^1.10.9",
|
|
73
81
|
"@swc/core": "1.10.18",
|
|
82
|
+
"@types/cli-progress": "^3",
|
|
74
83
|
"@types/ejs": "^3.1.5",
|
|
84
|
+
"@types/fs-extra": "^11",
|
|
75
85
|
"@types/node": "^18.19.76",
|
|
76
86
|
"@types/picomatch": "^3.0.2",
|
|
77
87
|
"@types/react": "^18.3.18",
|
package/styles/global.scss
CHANGED
|
@@ -89,3 +89,33 @@ td {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
|
|
93
|
+
@mixin print {
|
|
94
|
+
.rspress {
|
|
95
|
+
&-nav,
|
|
96
|
+
&-sidebar-menu,
|
|
97
|
+
&-doc-footer {
|
|
98
|
+
display: none;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
&-doc-container {
|
|
102
|
+
padding: 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&-directive-title::marker {
|
|
106
|
+
content: none;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
[class^='scroll-to-top_'] {
|
|
111
|
+
display: none;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.print:root {
|
|
116
|
+
@include print;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@media print {
|
|
120
|
+
@include print;
|
|
121
|
+
}
|