mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 14:48:08 +02:00
Replace Wintersmith with Metalsmith
Wintersmith is no longer maintained given that the most recent version is from six years ago, and all vulnerabilities that NPM reports originate from Wintersmith's dependencies. Metalsmith, and its plugins, on the other hand have recently had releases and don't have known vulnerabilities. In fact, the number of reported vulnerabilities by NPM even goes down to zero with this patch applied. This commit therefore replaces Wintersmith with Metalsmith by providing a transparent drop-in replacement, in a way that requires the least amount of changes to the code and the generated output. Note that this patch does update our versions of jQuery, Bootstrap and the Highlight.js theme because the previous versions were very outdated and didn't work correctly with Metalsmith. Moreover, those old versions contained vulnerabilities that are hereby fixed. Fixes #18198.
This commit is contained in:
parent
7279ce6bad
commit
ce7cdf4670
17 changed files with 1127 additions and 7261 deletions
63
gulpfile.mjs
63
gulpfile.mjs
|
@ -25,6 +25,10 @@ import crypto from "crypto";
|
|||
import { fileURLToPath } from "url";
|
||||
import fs from "fs";
|
||||
import gulp from "gulp";
|
||||
import hljs from "highlight.js";
|
||||
import layouts from "@metalsmith/layouts";
|
||||
import markdown from "@metalsmith/markdown";
|
||||
import Metalsmith from "metalsmith";
|
||||
import ordered from "ordered-read-streams";
|
||||
import path from "path";
|
||||
import postcss from "gulp-postcss";
|
||||
|
@ -33,6 +37,7 @@ import postcssDirPseudoClass from "postcss-dir-pseudo-class";
|
|||
import postcssDiscardComments from "postcss-discard-comments";
|
||||
import postcssNesting from "postcss-nesting";
|
||||
import { preprocess } from "./external/builder/builder.mjs";
|
||||
import relative from "metalsmith-html-relative";
|
||||
import rename from "gulp-rename";
|
||||
import replace from "gulp-replace";
|
||||
import stream from "stream";
|
||||
|
@ -2125,26 +2130,44 @@ function ghPagesPrepare() {
|
|||
]);
|
||||
}
|
||||
|
||||
gulp.task("wintersmith", async function () {
|
||||
const { default: wintersmith } = await import("wintersmith");
|
||||
const env = wintersmith("docs/config.json");
|
||||
|
||||
gulp.task("metalsmith", async function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
env.build(GH_PAGES_DIR, function (error) {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
replaceInFile(
|
||||
GH_PAGES_DIR + "/getting_started/index.html",
|
||||
/STABLE_VERSION/g,
|
||||
config.stableVersion
|
||||
);
|
||||
|
||||
console.log("Done building with wintersmith.");
|
||||
resolve();
|
||||
});
|
||||
Metalsmith(__dirname)
|
||||
.source("docs/contents")
|
||||
.destination(GH_PAGES_DIR)
|
||||
.clean(false)
|
||||
.metadata({
|
||||
sitename: "PDF.js",
|
||||
siteurl: "https://mozilla.github.io/pdf.js",
|
||||
description:
|
||||
"A general-purpose, web standards-based platform for parsing and rendering PDFs.",
|
||||
})
|
||||
.use(
|
||||
markdown({
|
||||
engineOptions: {
|
||||
highlight: (code, language) =>
|
||||
hljs.highlight(code, { language }).value,
|
||||
},
|
||||
})
|
||||
)
|
||||
.use(
|
||||
layouts({
|
||||
directory: "docs/templates",
|
||||
})
|
||||
)
|
||||
.use(relative())
|
||||
.build(error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
replaceInFile(
|
||||
`${GH_PAGES_DIR}/getting_started/index.html`,
|
||||
/STABLE_VERSION/g,
|
||||
config.stableVersion
|
||||
);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -2155,7 +2178,7 @@ gulp.task(
|
|||
"generic-legacy",
|
||||
"jsdoc",
|
||||
ghPagesPrepare,
|
||||
"wintersmith"
|
||||
"metalsmith"
|
||||
)
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue