Gildas 5 rokov pred
rodič
commit
59eb089c35
4 zmenil súbory, kde vykonal 51 pridanie a 8 odobranie
  1. 7 4
      cli/back-ends/puppeteer.js
  2. 1 1
      cli/single-file
  3. 42 2
      cli/single-file-cli-api.js
  4. 1 1
      package.json

+ 7 - 4
cli/back-ends/puppeteer.js

@@ -34,16 +34,19 @@ let browser;
 
 exports.initialize = async options => {
 	browser = await puppeteer.launch(getBrowserOptions(options));
+	return browser;
 };
 
-exports.getPageData = async options => {
-	let page;
+exports.getPageData = async (options, page) => {
+	const privatePage = !page;
 	try {
-		page = await browser.newPage();
+		if (privatePage) {
+			page = await browser.newPage();
+		}
 		await setPageOptions(page, options);
 		return await getPageData(browser, page, options);
 	} finally {
-		if (page) {
+		if (privatePage) {
 			await page.close();
 		}
 	}

+ 1 - 1
cli/single-file

@@ -31,7 +31,7 @@ run(require("./args"))
 	.catch(error => console.error(error.message || error)); // eslint-disable-line no-console	
 
 async function run(options) {
-	const singlefile = await require("./single-file-cli-api")(options);
+	const singlefile = await require("./single-file-cli-api").initialize(options);
 	let urls;
 	if (options.url && !singlefile.VALID_URL_TEST.test(options.url)) {
 		options.url = fileUrl(options.url);

+ 42 - 2
cli/single-file-cli-api.js

@@ -21,12 +21,48 @@
  *   Source.
  */
 
-/* global require, module, URL */
+/* global require, exports, URL */
 
 const fs = require("fs");
 const path = require("path");
 const VALID_URL_TEST = /^(https?|file):\/\//;
 
+const DEFAULT_OPTIONS = {
+	removeHiddenElements: true,
+	removeUnusedStyles: true,
+	removeUnusedFonts: true,
+	removeFrames: false,
+	removeImports: true,
+	removeScripts: true,
+	compressHTML: true,
+	compressCSS: false,
+	loadDeferredImages: true,
+	loadDeferredImagesMaxIdleTime: 1500,
+	loadDeferredImagesBlockCookies: false,
+	loadDeferredImagesBlockStorage: false,
+	loadDeferredImagesKeepZoomLevel: false,
+	filenameTemplate: "{page-title} ({date-locale} {time-locale}).html",
+	infobarTemplate: "",
+	includeInfobar: false,
+	filenameMaxLength: 192,
+	filenameReplacedCharacters: ["~", "+", "\\\\", "?", "%", "*", ":", "|", "\"", "<", ">", "\x00-\x1f", "\x7F"],
+	filenameReplacementCharacter: "_",
+	maxResourceSizeEnabled: false,
+	maxResourceSize: 10,
+	removeAudioSrc: true,
+	removeVideoSrc: true,
+	backgroundSave: true,
+	removeAlternativeFonts: true,
+	removeAlternativeMedias: true,
+	removeAlternativeImages: true,
+	groupDuplicateImages: true,
+	saveRawPage: false,
+	resolveFragmentIdentifierURLs: false,
+	userScriptEnabled: false,
+	saveFavicon: true,
+	includeBOM: false,
+	insertMetaNoIndex: false
+};
 const STATE_PROCESSING = "processing";
 const STATE_PROCESSED = "processed";
 
@@ -41,9 +77,13 @@ const backEnds = {
 };
 
 let backend, tasks = [], maxParallelWorkers = 8, sessionFilename;
-module.exports = initialize;
+
+exports.getBackEnd = backEndName => require(backEnds[backEndName]);
+exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
+exports.initialize = initialize;
 
 async function initialize(options) {
+	options = Object.assign({}, DEFAULT_OPTIONS, options);
 	maxParallelWorkers = options.maxParallelWorkers;
 	backend = require(backEnds[options.backEnd]);
 	await backend.initialize(options);

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 	"name": "single-file",
-	"version": "0.2.8",
+	"version": "0.3.0",
 	"description": "SingleFile",
 	"author": "Gildas Lormeau",
 	"license": "AGPL-3.0-or-later",