Explorar o código

remove missing favicons

Gildas %!s(int64=7) %!d(string=hai) anos
pai
achega
08bc32f668
Modificáronse 1 ficheiros con 15 adicións e 11 borrados
  1. 15 11
      lib/single-file/single-file-core.js

+ 15 - 11
lib/single-file/single-file-core.js

@@ -675,7 +675,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 		async pageResources() {
 			const resourcePromises = [
-				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("link[href][rel*=\"icon\"]"), "href", PREFIX_DATA_URI_IMAGE, this.baseURI, this.batchRequest, this.options),
+				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("link[href][rel*=\"icon\"]"), "href", PREFIX_DATA_URI_IMAGE, this.baseURI, this.batchRequest, this.options, false, true),
 				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("object[type=\"image/svg+xml\"], object[type=\"image/svg-xml\"]"), "data", PREFIX_DATA_URI_IMAGE_SVG, this.baseURI, this.batchRequest, this.options),
 				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("img[src], input[src][type=image]"), "src", PREFIX_DATA_URI_IMAGE, this.baseURI, this.batchRequest, this.options, true),
 				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("embed[src*=\".svg\"]"), "src", PREFIX_DATA_URI_IMAGE_SVG, this.baseURI, this.batchRequest, this.options),
@@ -1067,7 +1067,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			}
 		}
 
-		static async processAttribute(doc, resourceElements, attributeName, prefixDataURI, baseURI, batchRequest, options, processDuplicates) {
+		static async processAttribute(doc, resourceElements, attributeName, prefixDataURI, baseURI, batchRequest, options, processDuplicates, removeElementIfMissing) {
 			await Promise.all(Array.from(resourceElements).map(async resourceElement => {
 				let resourceURL = resourceElement.getAttribute(attributeName);
 				if (resourceURL) {
@@ -1075,19 +1075,23 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 					if (resourceURL && resourceURL != baseURI && DomUtil.testValidPath(resourceURL)) {
 						try {
 							const { content, indexResource, duplicate } = await batchRequest.addURL(new URL(resourceURL, baseURI).href);
-							if (content.startsWith(prefixDataURI) || content.startsWith(PREFIX_DATA_URI_NO_MIMETYPE) || content.startsWith(PREFIX_DATA_URI_OCTET_STREAM)) {
-								if (processDuplicates && duplicate && options.groupDuplicateImages) {
-									if (resourceElement.style.getPropertyValue("background-image")) {
-										resourceElement.setAttribute(attributeName, content);
+							if (removeElementIfMissing && content == EMPTY_DATA_URI) {
+								resourceElement.remove();
+							} else {
+								if (content.startsWith(prefixDataURI) || content.startsWith(PREFIX_DATA_URI_NO_MIMETYPE) || content.startsWith(PREFIX_DATA_URI_OCTET_STREAM)) {
+									if (processDuplicates && duplicate && options.groupDuplicateImages) {
+										if (resourceElement.style.getPropertyValue("background-image")) {
+											resourceElement.setAttribute(attributeName, content);
+										} else {
+											DomUtil.replaceImageSource(resourceElement, SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource, options);
+											DomUtil.insertVariable(doc, indexResource, content, options);
+										}
 									} else {
-										DomUtil.replaceImageSource(resourceElement, SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource, options);
-										DomUtil.insertVariable(doc, indexResource, content, options);
+										resourceElement.setAttribute(attributeName, content);
 									}
 								} else {
-									resourceElement.setAttribute(attributeName, content);
+									resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
 								}
-							} else {
-								resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
 							}
 						} catch (error) {
 							resourceElement.setAttribute(attributeName, EMPTY_IMAGE);