forked from cnrancher/docs-rancher2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pdf-generate.js
executable file
·70 lines (64 loc) · 1.76 KB
/
pdf-generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
const chalk = require("chalk");
const fs = require("fs");
var pdf = require("docusaurus-pdf/lib");
const docs_dir = process.env.DOCS_OUTPUT || "build_docs/RancherCNDocsPDF";
var docs = {
harverster: {
filename: "Harvester.pdf",
},
k3s: {
filename: "K3s.pdf",
},
octopus: {
index: "/about/_index/",
filename: "Octopus_CN_Doc.pdf",
},
rancher1: {
filename: "rancher1.6.pdf",
},
rancher2: {
filename: "Rancher2.x_CN_Doc.pdf",
},
rke: {
filename: "rke.pdf",
},
};
fs.mkdirSync(docs_dir, (options = { recursive: true }));
var pdfCacheId = "";
Object.keys(require.cache).forEach((k) => {
if (k.includes("docusaurus-pdf/lib")) {
pdfCacheId = k;
}
});
var p = Promise.resolve();
fs.readdirSync("docs").forEach((dirname) => {
var config = docs[dirname] || {};
var index = config["index"] || "/_index/";
var url = "/docs/" + dirname + index;
var filename = config["filename"] || dirname + ".pdf";
filename = docs_dir + "/" + filename;
p = p
.then(async () => {
try {
delete require.cache[pdfCacheId];
pdf = require("docusaurus-pdf/lib");
const res = await pdf.generatePdfFromBuildSources(
"./build/",
url,
"",
filename,
["--no-sandbox"]
);
console.log("pdf generated for", filename);
} catch (err) {
throw err;
}
})
.catch((err) => {
console.log(
chalk.red("failed to generate pdf", filename, ",", err)
);
process.exit(1);
});
});