@alauda/doom 1.10.11 → 1.11.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.js +1 -1
- package/lib/cli/load-config.js +7 -6
- package/lib/global/SiteOverrides/index.js +0 -1
- package/lib/global/VersionsNav/index.js +3 -4
- package/lib/plugins/index.d.ts +0 -1
- package/lib/plugins/index.js +0 -1
- package/lib/runtime/components/ExternalSiteLink.js +2 -3
- package/lib/runtime/components/OpenAPIPath.js +2 -3
- package/lib/runtime/components/OpenAPIRef.js +2 -3
- package/lib/runtime/components/Overview.js +4 -9
- package/lib/runtime/components/_utils.d.ts +1 -1
- package/lib/runtime/components/_utils.js +2 -4
- package/lib/theme.js +3 -5
- package/package.json +27 -30
- package/LICENSE +0 -21
- package/README.md +0 -29
- package/lib/cli/export-pdf-core/generatePdf.d.ts +0 -25
- package/lib/cli/export-pdf-core/generatePdf.js +0 -91
- package/lib/cli/export-pdf-core/index.d.ts +0 -3
- package/lib/cli/export-pdf-core/index.js +0 -3
- package/lib/cli/export-pdf-core/types.d.ts +0 -15
- package/lib/cli/export-pdf-core/types.js +0 -1
- package/lib/cli/export-pdf-core/utils/convertPathToPosix.d.ts +0 -8
- package/lib/cli/export-pdf-core/utils/convertPathToPosix.js +0 -26
- package/lib/cli/export-pdf-core/utils/getUrlLink.d.ts +0 -4
- package/lib/cli/export-pdf-core/utils/getUrlLink.js +0 -7
- package/lib/cli/export-pdf-core/utils/index.d.ts +0 -3
- package/lib/cli/export-pdf-core/utils/index.js +0 -3
- package/lib/cli/export-pdf-core/utils/mergePDF.d.ts +0 -26
- package/lib/cli/export-pdf-core/utils/mergePDF.js +0 -137
- package/lib/cli/html-export-pdf/core/index.d.ts +0 -3
- package/lib/cli/html-export-pdf/core/index.js +0 -3
- package/lib/cli/html-export-pdf/core/outline.d.ts +0 -47
- package/lib/cli/html-export-pdf/core/outline.js +0 -217
- package/lib/cli/html-export-pdf/core/postprocesser.d.ts +0 -14
- package/lib/cli/html-export-pdf/core/postprocesser.js +0 -36
- package/lib/cli/html-export-pdf/core/printer.d.ts +0 -59
- package/lib/cli/html-export-pdf/core/printer.js +0 -235
- package/lib/cli/html-export-pdf/index.d.ts +0 -2
- package/lib/cli/html-export-pdf/index.js +0 -2
- package/lib/cli/html-export-pdf/utils/cliProgress.d.ts +0 -13
- package/lib/cli/html-export-pdf/utils/cliProgress.js +0 -80
- package/lib/cli/html-export-pdf/utils/fs.d.ts +0 -5
- package/lib/cli/html-export-pdf/utils/fs.js +0 -18
- package/lib/cli/html-export-pdf/utils/getAbsFileName.d.ts +0 -1
- package/lib/cli/html-export-pdf/utils/getAbsFileName.js +0 -4
- package/lib/cli/html-export-pdf/utils/getDirname.d.ts +0 -1
- package/lib/cli/html-export-pdf/utils/getDirname.js +0 -5
- package/lib/cli/html-export-pdf/utils/index.d.ts +0 -7
- package/lib/cli/html-export-pdf/utils/index.js +0 -7
- package/lib/cli/html-export-pdf/utils/isValidUrl.d.ts +0 -1
- package/lib/cli/html-export-pdf/utils/isValidUrl.js +0 -3
- package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.d.ts +0 -2
- package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.js +0 -6
- package/lib/cli/html-export-pdf/utils/replaceExt.d.ts +0 -1
- package/lib/cli/html-export-pdf/utils/replaceExt.js +0 -19
- package/lib/cli/merge-pdfs/formatDate.d.ts +0 -1
- package/lib/cli/merge-pdfs/formatDate.js +0 -23
- package/lib/cli/merge-pdfs/index.d.ts +0 -8
- package/lib/cli/merge-pdfs/index.js +0 -62
- package/lib/plugins/sitemap/index.d.ts +0 -16
- package/lib/plugins/sitemap/index.js +0 -51
- package/pyodide/README.md +0 -90
- package/pyodide/console.html +0 -259
- package/pyodide/ffi.d.ts +0 -1118
- package/pyodide/micropip-0.8.0-py3-none-any.whl +0 -0
- package/pyodide/package.json +0 -59
- package/pyodide/packaging-24.2-py3-none-any.whl +0 -0
- package/pyodide/pyodide-lock.json +0 -1
- package/pyodide/pyodide.asm.js +0 -17
- package/pyodide/pyodide.asm.wasm +0 -0
- package/pyodide/pyodide.d.ts +0 -1627
- package/pyodide/pyodide.js +0 -6
- package/pyodide/pyodide.js.map +0 -1
- package/pyodide/pyodide.mjs +0 -4
- package/pyodide/pyodide.mjs.map +0 -1
- package/pyodide/pypdf-3.8.1-py3-none-any.whl +0 -0
- package/pyodide/python_stdlib.zip +0 -0
- package/pyodide/repodata.json +0 -1
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import process from 'node:process';
|
|
4
|
-
import { PDFDocument } from 'pdf-lib';
|
|
5
|
-
import { chromium } from 'playwright';
|
|
6
|
-
import { red } from 'yoctocolors';
|
|
7
|
-
import { getOutlineNodes, setOutlineNodes, } from './outline.js';
|
|
8
|
-
import { setMetadata } from './postprocesser.js';
|
|
9
|
-
export class Printer extends EventEmitter {
|
|
10
|
-
debug;
|
|
11
|
-
headless;
|
|
12
|
-
allowLocal;
|
|
13
|
-
outlineTags;
|
|
14
|
-
allowRemote;
|
|
15
|
-
initScripts;
|
|
16
|
-
additionalScripts;
|
|
17
|
-
additionalStyles;
|
|
18
|
-
allowedPaths;
|
|
19
|
-
allowedDomains;
|
|
20
|
-
ignoreHTTPSErrors;
|
|
21
|
-
browserWSEndpoint;
|
|
22
|
-
browserArgs;
|
|
23
|
-
timeout;
|
|
24
|
-
emulateMedia;
|
|
25
|
-
enableWarnings;
|
|
26
|
-
outlineContainerSelector;
|
|
27
|
-
browser;
|
|
28
|
-
browserContext;
|
|
29
|
-
page;
|
|
30
|
-
url;
|
|
31
|
-
constructor(options = {}) {
|
|
32
|
-
super();
|
|
33
|
-
this.debug = options.debug ?? false;
|
|
34
|
-
this.headless = options.headless ?? true;
|
|
35
|
-
this.allowLocal = options.allowLocal ?? false;
|
|
36
|
-
this.allowRemote = options.allowRemote ?? true;
|
|
37
|
-
this.outlineTags = options.outlineTags ?? [
|
|
38
|
-
'h1',
|
|
39
|
-
'h2',
|
|
40
|
-
'h3',
|
|
41
|
-
'h4',
|
|
42
|
-
'h5',
|
|
43
|
-
'h6',
|
|
44
|
-
];
|
|
45
|
-
this.initScripts = options.initScripts ?? [];
|
|
46
|
-
this.additionalScripts = options.additionalScripts ?? [];
|
|
47
|
-
this.additionalStyles = options.additionalStyles ?? [];
|
|
48
|
-
this.allowedPaths = options.allowedPaths ?? [];
|
|
49
|
-
this.allowedDomains = options.allowedDomains ?? [];
|
|
50
|
-
this.ignoreHTTPSErrors = options.ignoreHTTPSErrors ?? false;
|
|
51
|
-
this.browserWSEndpoint = options.browserEndpoint;
|
|
52
|
-
this.browserArgs = options.browserArgs ?? [];
|
|
53
|
-
this.timeout = options.timeout ?? 0;
|
|
54
|
-
this.emulateMedia = options.emulateMedia ?? 'print';
|
|
55
|
-
this.enableWarnings = options.enableWarnings ?? false;
|
|
56
|
-
this.outlineContainerSelector = options.outlineContainerSelector ?? '';
|
|
57
|
-
if (this.debug) {
|
|
58
|
-
this.headless = false;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async setup(launchOptions) {
|
|
62
|
-
if (this.page) {
|
|
63
|
-
return this.page;
|
|
64
|
-
}
|
|
65
|
-
const browserOptions = {
|
|
66
|
-
pipe: true,
|
|
67
|
-
headless: this.headless,
|
|
68
|
-
args: ['--disable-dev-shm-usage', '--export-tagged-pdf'],
|
|
69
|
-
...launchOptions,
|
|
70
|
-
};
|
|
71
|
-
if (this.allowLocal) {
|
|
72
|
-
browserOptions.args.push('--allow-file-access-from-files');
|
|
73
|
-
}
|
|
74
|
-
if (this.browserArgs.length) {
|
|
75
|
-
browserOptions.args.push(...this.browserArgs);
|
|
76
|
-
}
|
|
77
|
-
if (this.browserWSEndpoint) {
|
|
78
|
-
this.browser = await chromium.connect(this.browserWSEndpoint, browserOptions);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
this.browser = await chromium.launch(browserOptions);
|
|
82
|
-
}
|
|
83
|
-
this.browserContext = await this.browser.newContext({
|
|
84
|
-
ignoreHTTPSErrors: this.ignoreHTTPSErrors,
|
|
85
|
-
});
|
|
86
|
-
for (const script of this.initScripts) {
|
|
87
|
-
await this.browserContext.addInitScript(script);
|
|
88
|
-
}
|
|
89
|
-
const page = await this.browserContext.newPage();
|
|
90
|
-
this.page = page;
|
|
91
|
-
await page.emulateMedia({
|
|
92
|
-
colorScheme: 'light',
|
|
93
|
-
media: this.emulateMedia,
|
|
94
|
-
});
|
|
95
|
-
if (this.needsAllowedRules()) {
|
|
96
|
-
await page.route('**/*', (route) => {
|
|
97
|
-
const uri = new URL(route.request().url());
|
|
98
|
-
const { host, protocol, pathname } = uri;
|
|
99
|
-
const local = protocol === 'file:';
|
|
100
|
-
if (local && !this.withinAllowedPath(pathname)) {
|
|
101
|
-
return route.abort();
|
|
102
|
-
}
|
|
103
|
-
if (local && !this.allowLocal) {
|
|
104
|
-
return route.abort();
|
|
105
|
-
}
|
|
106
|
-
if (host && !this.isAllowedDomain(host)) {
|
|
107
|
-
return route.abort();
|
|
108
|
-
}
|
|
109
|
-
if (host && !this.allowRemote) {
|
|
110
|
-
return route.abort();
|
|
111
|
-
}
|
|
112
|
-
return route.continue();
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return page;
|
|
116
|
-
}
|
|
117
|
-
async render(url) {
|
|
118
|
-
const page = this.page || (await this.setup());
|
|
119
|
-
if (url === this.url) {
|
|
120
|
-
return page;
|
|
121
|
-
}
|
|
122
|
-
this.url = url;
|
|
123
|
-
try {
|
|
124
|
-
await page.goto(url);
|
|
125
|
-
for (const style of this.additionalStyles) {
|
|
126
|
-
await page.addStyleTag({ path: style });
|
|
127
|
-
}
|
|
128
|
-
for (const script of this.additionalScripts) {
|
|
129
|
-
await page.addScriptTag({ path: script });
|
|
130
|
-
}
|
|
131
|
-
await page.waitForLoadState('networkidle', { timeout: this.timeout });
|
|
132
|
-
return page;
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
await this.closeBrowser();
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
async pdf(url, options = {}, pdfOutlines) {
|
|
140
|
-
const page = await this.render(url);
|
|
141
|
-
try {
|
|
142
|
-
// Get metatags
|
|
143
|
-
const meta = await page.evaluate(() => {
|
|
144
|
-
const meta = {};
|
|
145
|
-
const title = document.querySelector('title');
|
|
146
|
-
if (title) {
|
|
147
|
-
meta.title = title.textContent.trim();
|
|
148
|
-
}
|
|
149
|
-
const lang = document.querySelector('html')?.getAttribute('lang');
|
|
150
|
-
if (lang) {
|
|
151
|
-
meta.lang = lang;
|
|
152
|
-
}
|
|
153
|
-
const metaTags = document.querySelectorAll('meta');
|
|
154
|
-
metaTags.forEach((tag) => {
|
|
155
|
-
if (tag.name) {
|
|
156
|
-
meta[tag.name] = tag.content;
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return meta;
|
|
160
|
-
});
|
|
161
|
-
const pdfExportOptions = {
|
|
162
|
-
scale: !options.scale ? 1 : options.scale,
|
|
163
|
-
displayHeaderFooter: false,
|
|
164
|
-
headerTemplate: options.headerTemplate,
|
|
165
|
-
footerTemplate: options.footerTemplate,
|
|
166
|
-
preferCSSPageSize: options.preferCSSPageSize,
|
|
167
|
-
printBackground: options.printBackground,
|
|
168
|
-
width: options.width,
|
|
169
|
-
height: options.height,
|
|
170
|
-
landscape: options.landscape,
|
|
171
|
-
format: options.format,
|
|
172
|
-
};
|
|
173
|
-
if (options.margin) {
|
|
174
|
-
pdfExportOptions.margin = options.margin;
|
|
175
|
-
}
|
|
176
|
-
if (options.pageRanges) {
|
|
177
|
-
pdfExportOptions.pageRanges = options.pageRanges;
|
|
178
|
-
}
|
|
179
|
-
if (options.headerTemplate || options.footerTemplate) {
|
|
180
|
-
pdfExportOptions.displayHeaderFooter = true;
|
|
181
|
-
}
|
|
182
|
-
const pdf = await page.pdf(pdfExportOptions);
|
|
183
|
-
this.emit('postprocessing');
|
|
184
|
-
const pdfDoc = await PDFDocument.load(pdf);
|
|
185
|
-
setMetadata(pdfDoc, meta);
|
|
186
|
-
let outlineNodes = [];
|
|
187
|
-
if (pdfOutlines) {
|
|
188
|
-
outlineNodes = await getOutlineNodes(page, this.outlineTags, this.outlineContainerSelector);
|
|
189
|
-
setOutlineNodes(pdfDoc, outlineNodes, this.enableWarnings);
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
data: await pdfDoc.save(),
|
|
193
|
-
outlineNodes,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
await this.closeBrowser();
|
|
198
|
-
throw error;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
async closeBrowser() {
|
|
202
|
-
if (this.browser) {
|
|
203
|
-
await this.browser.close();
|
|
204
|
-
this.browser = undefined;
|
|
205
|
-
this.browserContext = undefined;
|
|
206
|
-
this.page = undefined;
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
process.stdout.write(red('Browser instance not found'));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
needsAllowedRules() {
|
|
213
|
-
return this.allowedPaths.length || this.allowedDomains.length;
|
|
214
|
-
}
|
|
215
|
-
withinAllowedPath(pathname) {
|
|
216
|
-
if (!this.allowedPaths.length) {
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
for (const parent of this.allowedPaths) {
|
|
220
|
-
const relative = path.relative(parent, pathname);
|
|
221
|
-
if (relative &&
|
|
222
|
-
!relative.startsWith('..') &&
|
|
223
|
-
!path.isAbsolute(relative)) {
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
isAllowedDomain(domain) {
|
|
230
|
-
if (!this.allowedDomains.length) {
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
return this.allowedDomains.includes(domain);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SingleBar } from 'cli-progress';
|
|
2
|
-
export declare function createProgress(indeterminate?: boolean): {
|
|
3
|
-
bar: SingleBar;
|
|
4
|
-
start(total: number): void;
|
|
5
|
-
updateNumber(v: number): void;
|
|
6
|
-
increment(step: number, { txt, headTitle }?: {
|
|
7
|
-
txt?: string;
|
|
8
|
-
headTitle?: string;
|
|
9
|
-
}): void;
|
|
10
|
-
updateText(t: string): void;
|
|
11
|
-
updateTitle(t: string): void;
|
|
12
|
-
stop(): void;
|
|
13
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Presets, SingleBar } from 'cli-progress';
|
|
2
|
-
import { blue, cyan, dim, green, yellow } from 'yoctocolors';
|
|
3
|
-
function replaceTitle(title) {
|
|
4
|
-
return title.length ? `|| ${title}` : '';
|
|
5
|
-
}
|
|
6
|
-
export function createProgress(indeterminate = false) {
|
|
7
|
-
function getSpinner(n = 0) {
|
|
8
|
-
return [cyan('●'), green('◆'), blue('■'), yellow('▲')][n % 4];
|
|
9
|
-
}
|
|
10
|
-
let current = 0;
|
|
11
|
-
let spinner = 0;
|
|
12
|
-
let text = 'Generating';
|
|
13
|
-
let title = '';
|
|
14
|
-
let timer;
|
|
15
|
-
const progress = new SingleBar({
|
|
16
|
-
clearOnComplete: false,
|
|
17
|
-
hideCursor: true,
|
|
18
|
-
format: ` {spin} {text} ${indeterminate ? dim(yellow('...')) : ' {bar} {value}/{total}'} {title} `,
|
|
19
|
-
linewrap: false,
|
|
20
|
-
barsize: 30,
|
|
21
|
-
}, Presets.shades_grey);
|
|
22
|
-
return {
|
|
23
|
-
bar: progress,
|
|
24
|
-
start(total) {
|
|
25
|
-
progress.start(total, 0, {
|
|
26
|
-
spin: getSpinner(spinner),
|
|
27
|
-
text,
|
|
28
|
-
title: replaceTitle(title),
|
|
29
|
-
});
|
|
30
|
-
timer = setInterval(() => {
|
|
31
|
-
spinner += 1;
|
|
32
|
-
progress.update({
|
|
33
|
-
spin: getSpinner(spinner),
|
|
34
|
-
text,
|
|
35
|
-
title: replaceTitle(title),
|
|
36
|
-
});
|
|
37
|
-
}, 200);
|
|
38
|
-
},
|
|
39
|
-
updateNumber(v) {
|
|
40
|
-
current = v;
|
|
41
|
-
progress.update(v, {
|
|
42
|
-
spin: getSpinner(spinner),
|
|
43
|
-
text,
|
|
44
|
-
title: replaceTitle(title),
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
increment(step, { txt, headTitle } = {
|
|
48
|
-
txt: '',
|
|
49
|
-
headTitle: '',
|
|
50
|
-
}) {
|
|
51
|
-
text = txt?.length ? txt : text;
|
|
52
|
-
title = headTitle?.length ? headTitle : title;
|
|
53
|
-
progress.increment(step, {
|
|
54
|
-
spin: getSpinner(spinner),
|
|
55
|
-
text,
|
|
56
|
-
title: replaceTitle(title),
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
updateText(t) {
|
|
60
|
-
text = t;
|
|
61
|
-
progress.update(current, {
|
|
62
|
-
spin: getSpinner(spinner),
|
|
63
|
-
text,
|
|
64
|
-
title: replaceTitle(title),
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
updateTitle(t) {
|
|
68
|
-
title = t;
|
|
69
|
-
progress.update(current, {
|
|
70
|
-
spin: getSpinner(spinner),
|
|
71
|
-
text,
|
|
72
|
-
title: replaceTitle(title),
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
stop() {
|
|
76
|
-
clearInterval(timer);
|
|
77
|
-
progress.stop();
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { existsSync, promises as fs } from 'node:fs';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getAbsFileName(metaURL: string): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getDirname(metaURL: string): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isValidUrl(url: string): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function replaceExt(npath: string, ext: string): string;
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function formatDate(date: Date): string;
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
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;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { yellowBright } from 'yoctocolors';
|
|
3
|
-
import _pyodide from '../../../pyodide/pyodide.js';
|
|
4
|
-
import { pkgResolve } from '../../utils/helpers.js';
|
|
5
|
-
import { formatDate } from './formatDate.js';
|
|
6
|
-
/**
|
|
7
|
-
* @see https://www.uuidgenerator.net/version4
|
|
8
|
-
* UUID v4
|
|
9
|
-
*/
|
|
10
|
-
export const MERGE_PDF_NAME = '66699f18-ad5a-43c2-a96e-97bddaef0e6b.pdf';
|
|
11
|
-
export const MOUNT_DIR = '/' + '991e729a-8f2e-472a-8402-c26bb03b5ea3';
|
|
12
|
-
export async function mergePDFs(entries) {
|
|
13
|
-
if (entries.length < 2) {
|
|
14
|
-
process.stdout.write(yellowBright('At least two PDF files.\n'));
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
const pyodideDir = pkgResolve('pyodide');
|
|
18
|
-
const pyodide = await _pyodide.loadPyodide({
|
|
19
|
-
indexURL: pyodideDir,
|
|
20
|
-
});
|
|
21
|
-
await pyodide.loadPackage('micropip');
|
|
22
|
-
const micropip = pyodide.pyimport('micropip');
|
|
23
|
-
pyodide.FS.mkdirTree(MOUNT_DIR);
|
|
24
|
-
pyodide.FS.mount(
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
26
|
-
pyodide.FS.filesystems.NODEFS, // type-coverage:ignore-line -- out of control
|
|
27
|
-
{ root: pyodideDir }, 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}/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;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type RspressPlugin } from '@rspress/core';
|
|
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;
|
|
@@ -1,51 +0,0 @@
|
|
|
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/core';
|
|
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.routePath)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
set.add(pageData.routePath);
|
|
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
|
-
}
|