Don't fetch or execute JavaScript
This commit is contained in:
parent
2236bb2a86
commit
a820bc517b
4 changed files with 19 additions and 5 deletions
|
|
@ -3,7 +3,7 @@ const path = require("path");
|
|||
const fs = require("mz/fs");
|
||||
const mkdirp = require("mkdirp-then");
|
||||
const request = require("requisition");
|
||||
const jsdom = require("jsdom");
|
||||
const jsdom = require("./jsdom.js");
|
||||
|
||||
const FILENAME_PREFIX = "chapter";
|
||||
const URL_SUFFIX = "-url.txt";
|
||||
|
|
@ -59,7 +59,7 @@ function downloadAllChapters(startChapterUrl, startChapterNumber, cachePath) {
|
|||
})
|
||||
.then(function (contents) {
|
||||
console.log("- Response body received");
|
||||
const rawChapterDoc = jsdom.jsdom(contents, { url: currentChapter });
|
||||
const rawChapterDoc = jsdom(contents, { url: currentChapter });
|
||||
console.log("- Response body parsed into DOM");
|
||||
|
||||
const chapterUrlToSave = currentChapter;
|
||||
|
|
|
|||
13
lib/jsdom.js
Normal file
13
lib/jsdom.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
"use strict";
|
||||
const jsdom = require("jsdom");
|
||||
const xtend = require("xtend");
|
||||
|
||||
// No need to fetch or execute JavaScript
|
||||
module.exports = function (contents, options) {
|
||||
options = xtend(options, { features: {
|
||||
FetchExternalResources: false,
|
||||
ProcessExternalResources: false
|
||||
}});
|
||||
|
||||
return jsdom.jsdom(contents, options);
|
||||
};
|
||||
|
|
@ -3,7 +3,7 @@ const path = require("path");
|
|||
const fs = require("mz/fs");
|
||||
const mkdirp = require("mkdirp-then");
|
||||
const rimraf = require("rimraf-then");
|
||||
const jsdom = require("jsdom");
|
||||
const jsdom = require("./jsdom.js");
|
||||
|
||||
const download = require("./download.js");
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ function convertChapter(filePath, i) {
|
|||
console.log(`- Reading ${filePath}`);
|
||||
return fs.readFile(filePath, { encoding: "utf-8" }).then(function (contents) {
|
||||
console.log(`- Read ${filePath}`);
|
||||
const rawChapterDoc = jsdom.jsdom(contents);
|
||||
const rawChapterDoc = jsdom(contents);
|
||||
const output = getChapterString(rawChapterDoc);
|
||||
|
||||
// TODO: this should probably not be necessary... jsdom bug I guess!?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue