Explorar el Código

transfomed code from finalize into tasks

Former-commit-id: 7a38c54a76c2310bb176d3b8883142657658003f
Gildas hace 6 años
padre
commit
cb0a6d6642
Se han modificado 1 ficheros con 46 adiciones y 38 borrados
  1. 46 38
      lib/single-file/single-file-core.js

+ 46 - 38
lib/single-file/single-file-core.js

@@ -135,6 +135,10 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			{ action: "replaceStyleAttributes" },
 			{ action: "insertVariables" },
 			{ option: "compressHTML", action: "compressHTML" }
+		],
+		parallel: [
+			{ option: "enableMaff", action: "insertMAFFMetaData" },
+			{ action: "setDocInfo" }
 		]
 	}];
 
@@ -401,49 +405,14 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			if (this.workStyleElement.parentNode) {
 				this.workStyleElement.remove();
 			}
+			this.doc.querySelectorAll("base").forEach(element => element.remove());
 			const metaCharset = this.doc.head.querySelector("meta[charset]");
 			if (metaCharset) {
 				this.doc.head.insertBefore(metaCharset, this.doc.head.firstChild);
-			}
-			this.doc.querySelectorAll("base").forEach(element => element.remove());
-			if (this.doc.head.querySelectorAll("*").length == 1 && metaCharset && this.doc.body.childNodes.length == 0) {
-				this.doc.head.querySelector("meta[charset]").remove();
-			}
-			if (this.maffMetaDataPromise) {
-				const maffMetaData = await this.maffMetaDataPromise;
-				if (maffMetaData && maffMetaData.content) {
-					const NAMESPACE_RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
-					const maffDoc = util.parseXMLContent(maffMetaData.content);
-					const originalURLElement = maffDoc.querySelector("RDF > Description > originalurl");
-					const archiveTimeElement = maffDoc.querySelector("RDF > Description > archivetime");
-					if (originalURLElement) {
-						this.options.saveUrl = originalURLElement.getAttributeNS(NAMESPACE_RDF, "resource");
-					}
-					if (archiveTimeElement) {
-						const value = archiveTimeElement.getAttributeNS(NAMESPACE_RDF, "resource");
-						if (value) {
-							const date = new Date(value);
-							if (!isNaN(date.getTime())) {
-								this.options.saveDate = new Date(value);
-							}
-						}
-					}
+				if (this.doc.head.querySelectorAll("*").length == 1 && this.doc.body.childNodes.length == 0) {
+					this.doc.head.querySelector("meta[charset]").remove();
 				}
 			}
-			const titleElement = this.doc.querySelector("title");
-			const descriptionElement = this.doc.querySelector("meta[name=description]");
-			const authorElement = this.doc.querySelector("meta[name=author]");
-			const creatorElement = this.doc.querySelector("meta[name=creator]");
-			const publisherElement = this.doc.querySelector("meta[name=publisher]");
-			this.options.title = titleElement ? titleElement.textContent.trim() : "";
-			this.options.infobarContent = await ProcessorHelper.evalTemplate(this.options.infobarTemplate, this.options, null, true);
-			this.options.info = {
-				description: descriptionElement && descriptionElement.content ? descriptionElement.content.trim() : "",
-				lang: this.doc.documentElement.lang,
-				author: authorElement && authorElement.content ? authorElement.content.trim() : "",
-				creator: creatorElement && creatorElement.content ? creatorElement.content.trim() : "",
-				publisher: publisherElement && publisherElement.content ? publisherElement.content.trim() : ""
-			};
 		}
 
 		async getPageData() {
@@ -1238,6 +1207,45 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 				this.stats.add("discarded", "HTML bytes", size - util.getContentSize(this.doc.documentElement.outerHTML));
 			}
 		}
+
+		async insertMAFFMetaData() {
+			const maffMetaData = await this.maffMetaDataPromise;
+			if (maffMetaData && maffMetaData.content) {
+				const NAMESPACE_RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+				const maffDoc = util.parseXMLContent(maffMetaData.content);
+				const originalURLElement = maffDoc.querySelector("RDF > Description > originalurl");
+				const archiveTimeElement = maffDoc.querySelector("RDF > Description > archivetime");
+				if (originalURLElement) {
+					this.options.saveUrl = originalURLElement.getAttributeNS(NAMESPACE_RDF, "resource");
+				}
+				if (archiveTimeElement) {
+					const value = archiveTimeElement.getAttributeNS(NAMESPACE_RDF, "resource");
+					if (value) {
+						const date = new Date(value);
+						if (!isNaN(date.getTime())) {
+							this.options.saveDate = new Date(value);
+						}
+					}
+				}
+			}
+		}
+
+		async setDocInfo() {
+			const titleElement = this.doc.querySelector("title");
+			const descriptionElement = this.doc.querySelector("meta[name=description]");
+			const authorElement = this.doc.querySelector("meta[name=author]");
+			const creatorElement = this.doc.querySelector("meta[name=creator]");
+			const publisherElement = this.doc.querySelector("meta[name=publisher]");
+			this.options.title = titleElement ? titleElement.textContent.trim() : "";
+			this.options.infobarContent = await ProcessorHelper.evalTemplate(this.options.infobarTemplate, this.options, null, true);
+			this.options.info = {
+				description: descriptionElement && descriptionElement.content ? descriptionElement.content.trim() : "",
+				lang: this.doc.documentElement.lang,
+				author: authorElement && authorElement.content ? authorElement.content.trim() : "",
+				creator: creatorElement && creatorElement.content ? creatorElement.content.trim() : "",
+				publisher: publisherElement && publisherElement.content ? publisherElement.content.trim() : ""
+			};
+		}
 	}
 
 	// ---------------