فهرست منبع

fixed issue #234

Former-commit-id: e67bd7545b476f625cd8fa8938a4ed376f4edc15
Gildas 6 سال پیش
والد
کامیت
5e51f77c47
1فایلهای تغییر یافته به همراه12 افزوده شده و 5 حذف شده
  1. 12 5
      lib/single-file/single-file-core.js

+ 12 - 5
lib/single-file/single-file-core.js

@@ -1405,12 +1405,13 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			removedRules.forEach(cssRule => stylesheet.children.remove(cssRule));
 		}
 
-		static async resolveImportURLs(stylesheetContent, baseURI, options, workStylesheet) {
+		static async resolveImportURLs(stylesheetContent, baseURI, options, workStylesheet, importedStyleSheets = new Set()) {
 			stylesheetContent = ProcessorHelper.resolveStylesheetURLs(stylesheetContent, baseURI);
 			const imports = Util.getImportFunctions(stylesheetContent);
 			await Promise.all(imports.map(async cssImport => {
 				const match = Util.matchImport(cssImport);
 				if (match) {
+					const regExpCssImport = Util.getRegExp(cssImport);
 					let resourceURL = Util.normalizeURL(match.resourceURL);
 					if (!Util.testIgnoredPath(resourceURL) && Util.testValidPath(resourceURL)) {
 						try {
@@ -1418,7 +1419,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 						} catch (error) {
 							// ignored
 						}
-						if (Util.testValidURL(resourceURL)) {
+						if (Util.testValidURL(resourceURL) && !importedStyleSheets.has(resourceURL)) {
+							importedStyleSheets.add(resourceURL);
 							const content = await util.getContent(resourceURL, {
 								maxResourceSize: options.maxResourceSize,
 								maxResourceSizeEnabled: options.maxResourceSizeEnabled,
@@ -1433,15 +1435,20 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 							}
 							importedStylesheetContent = Util.wrapMediaQuery(importedStylesheetContent, match.media);
 							if (stylesheetContent.includes(cssImport)) {
-								importedStylesheetContent = await ProcessorHelper.resolveImportURLs(importedStylesheetContent, resourceURL, options, workStylesheet);
+								importedStylesheetContent = await ProcessorHelper.resolveImportURLs(importedStylesheetContent, resourceURL, options, workStylesheet, importedStyleSheets);
 								workStylesheet.textContent = importedStylesheetContent;
 								if (workStylesheet.sheet.cssRules.length) {
-									stylesheetContent = stylesheetContent.replace(Util.getRegExp(cssImport), importedStylesheetContent);
+									stylesheetContent = stylesheetContent.replace(regExpCssImport, importedStylesheetContent);
 								} else {
-									stylesheetContent = stylesheetContent.replace(Util.getRegExp(cssImport), "");
+									stylesheetContent = stylesheetContent.replace(regExpCssImport, "");
 								}
 							}
+						} else {
+							importedStyleSheets.add(resourceURL);
+							stylesheetContent = stylesheetContent.replace(regExpCssImport, "");
 						}
+					} else {
+						stylesheetContent = stylesheetContent.replace(regExpCssImport, "");
 					}
 				}
 			}));