Quellcode durchsuchen

handle unfound fonts

Gildas vor 7 Jahren
Ursprung
Commit
27ce486fea
2 geänderte Dateien mit 3 neuen und 3 gelöschten Zeilen
  1. 2 1
      lib/single-file/css-fonts-minifier.js
  2. 1 2
      lib/single-file/single-file-core.js

+ 2 - 1
lib/single-file/css-fonts-minifier.js

@@ -37,6 +37,7 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 	const REGEXP_FONT_FORMAT = /\.([^.?#]+)((\?|#).*?)?$/;
 	const REGEXP_FONT_FORMAT_VALUE = /format\((.*?)\)\s*,?$/;
 	const REGEXP_FONT_SRC = /(.*?)\s*,?$/;
+	const EMPTY_URL_SOURCE = "url(\"data:base64,\") format(\"woff\")";
 	const PSEUDO_ELEMENTS = ["::after", "::before", "::first-line", "::first-letter", ":before", ":after", ":first-line", ":first-letter", "::placeholder", "::selection", "::marker", "::cue", "::slotted", "::spelling-error", "::grammar-error"];
 	const FONT_WEIGHTS = {
 		normal: 400,
@@ -223,7 +224,7 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 			}
 			return { src: fontSource.match(REGEXP_FONT_SRC)[1], format: fontFormat };
 		});
-		const fontTest = (fontSource, format) => fontSource.format == format;
+		const fontTest = (fontSource, format) => fontSource.src != EMPTY_URL_SOURCE && fontSource.format == format;
 		let woffFontFound = fontSources.find(fontSource => fontTest(fontSource, "woff2-variations"));
 		if (!woffFontFound) {
 			woffFontFound = fontSources.find(fontSource => fontTest(fontSource, "woff2"));

+ 1 - 2
lib/single-file/single-file-core.js

@@ -99,7 +99,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 	}, {
 		sequential: [
 			{ option: "removeUnusedStyles", action: "removeUnusedStyles" },
-			{ option: "removeAlternativeFonts", action: "removeAlternativeFonts" },
 			{ option: "removeAlternativeMedias", action: "removeAlternativeMedias" }
 		],
 		parallel: [
@@ -111,7 +110,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 	}, {
 		sequential: [
 			{ option: "lazyLoadImages", action: "lazyLoadImages" },
-			{ option: "removeAlternativeFonts", action: "postRemoveAlternativeFonts" },
+			{ option: "removeAlternativeFonts", action: "removeAlternativeFonts" },
 			{ option: "compressCSS", action: "compressCSS" }
 		],
 		parallel: [