@@ -27,7 +27,12 @@ class Webfonts
27
27
protected bool $ wordpress = false ;
28
28
29
29
/**
30
- * The exception list.
30
+ * The fonts to allow.
31
+ */
32
+ public static array $ only = [];
33
+
34
+ /**
35
+ * The fonts to exclude.
31
36
*/
32
37
public static array $ except = [];
33
38
@@ -74,19 +79,29 @@ public static function except(array $except): void
74
79
static ::$ except = [...static ::$ except , ...$ except ];
75
80
}
76
81
82
+ /**
83
+ * Set the fonts to allow.
84
+ */
85
+ public static function only (array $ only ): void
86
+ {
87
+ static ::$ only = [...static ::$ only , ...$ only ];
88
+ }
89
+
77
90
/**
78
91
* Retrieve the fonts from the manifest.
79
92
*/
80
- public function fonts (array $ except = []): array
93
+ public function fonts (array $ except = [], array $ only = [] ): array
81
94
{
82
95
if ($ this ->fonts ) {
83
96
return $ this ->fonts ;
84
97
}
85
98
86
99
$ except = [...static ::$ except , ...$ except ];
100
+ $ only = [...static ::$ only , ...$ only ];
87
101
88
102
return collect ($ this ->manifest ())
89
103
->filter (fn ($ value , $ key ) => Str::endsWith ($ key , '.woff2 ' ))
104
+ ->filter (fn ($ value , $ key ) => blank ($ only ) || in_array (basename ($ key ), $ only ) || in_array (basename ($ key , '.woff2 ' ), $ only ))
90
105
->reject (fn ($ value , $ key ) => in_array (basename ($ key ), $ except ) || in_array (basename ($ key , '.woff2 ' ), $ except ))
91
106
->all ();
92
107
}
0 commit comments