├── .editorconfig ├── .gitignore ├── .prettierrc ├── LICENSE.md ├── README.md ├── composer.json ├── resources └── views │ └── font-face.blade.php └── src ├── Console └── Commands │ └── WebfontsAddCommand.php ├── Facades └── Webfonts.php ├── PreloadWebfonts.php ├── Webfonts.php └── WebfontsServiceProvider.php /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 2 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.php] 15 | indent_size = 4 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "trailingComma": "es5" 5 | } 6 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Brandon Nifong 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Webfonts 2 | 3 | ![Latest Stable Version](https://img.shields.io/packagist/v/log1x/laravel-webfonts.svg?style=flat-square) 4 | ![Total Downloads](https://img.shields.io/packagist/dt/log1x/laravel-webfonts.svg?style=flat-square) 5 | ![Build Status](https://img.shields.io/github/actions/workflow/status/log1x/laravel-webfonts/main.yml?branch=main&style=flat-square) 6 | 7 | Laravel Webfonts allows you to easily download, install, and preload over 1500 Google fonts locally in your Laravel project. 8 | 9 | ![Demo](https://i.imgur.com/JgotyKK.gif) 10 | 11 | ## Features 12 | 13 | - 🔍️ Search and install over 1500 Google fonts from the public [google-webfonts-helper](https://github.com/majodev/google-webfonts-helper) API. 14 | - ⚡️ Automatically generate `@font-face` CSS `at-rules` when installing fonts using CLI. 15 | - 🧑‍💻 Supports [Vite](https://vitejs.dev/) out of the box with zero configuration. 16 | - ⚡️ Provides an easy-to-use `@preloadFonts` Blade directive to preload fonts found in the Vite manifest. 17 | - 🚀 Automatically injects font preload markup into `wp_head` on WordPress sites running [Acorn](https://github.com/roots/acorn). 18 | 19 | ## Requirements 20 | 21 | - [PHP](https://secure.php.net/manual/en/install.php) >= 8.1 22 | - [Composer](https://getcomposer.org/download/) 23 | - [Laravel](https://github.com/laravel/laravel) >= 10.0 24 | 25 | ## Installation 26 | 27 | Install via Composer: 28 | 29 | ```sh 30 | $ composer require log1x/laravel-webfonts 31 | ``` 32 | 33 | ## Usage 34 | 35 | If you already have fonts locally installed in your project, skip to [Preloading Fonts](#preloading-fonts). 36 | 37 | ### Adding Fonts 38 | 39 | Laravel Webfonts provides a very easy way to install new webfonts to your project using command line: 40 | 41 | ```sh 42 | artisan webfonts:add 43 | ``` 44 | 45 | By default, installing a font will trigger the following things to happen: 46 | 47 | - Download the font archive to a temporary directory in local storage. 48 | - Extract the font archive. 49 | - Move downloaded fonts to `resources/fonts`. 50 | - Clean up the temporary directory. 51 | - Generate and prepend `@font-face` at-rules to a `fonts` stylesheet. 52 | 53 | The fonts stylesheet will reside at the root of your stylesheet directory located in `resources/`. If the font stylesheet does not already exist, it will be created using the most common stylesheet extension (css, scss, ...) found among your styles. 54 | 55 | By default, the `resources/css` and `resources/styles` directories are automatically scanned for existing files to find the appropriate place to write the fonts stylesheet. 56 | 57 | The generated `@font-face` at-rules will look like this: 58 | 59 | ```css 60 | @font-face { 61 | font-display: swap; 62 | font-family: 'Roboto'; 63 | font-style: normal; 64 | font-weight: 400; 65 | src: url('../fonts/roboto-v30-latin-regular.woff2') format('woff2'); 66 | } 67 | 68 | @font-face { 69 | font-display: swap; 70 | font-family: 'Roboto'; 71 | font-style: italic; 72 | font-weight: 400; 73 | src: url('../fonts/roboto-v30-latin-italic.woff2') format('woff2'); 74 | } 75 | ``` 76 | 77 | Adding additional fonts will cause them to be prepended to the existing `fonts` stylesheet. 78 | 79 | ### Importing Fonts 80 | 81 | When fonts are installed for the first time, a `fonts` stylesheet is created in your project's stylesheet folder. In a vanilla Laravel project, this is typically `resources/css/fonts.css`. 82 | 83 | You must import the generated `fonts` file into your project's primary stylesheet (e.g. `app.css`). If you're using Tailwind, it would look something like: 84 | 85 | ```css 86 | @import 'fonts'; 87 | 88 | @tailwind base; 89 | @tailwind components; 90 | @tailwind utilities; 91 | ``` 92 | 93 | ### Preloading Fonts 94 | 95 | > [!NOTE] 96 | > If you are using WordPress alongside [Acorn](https://github.com/roots/acorn), you can ignore this section as preloading is automatically handled for you inside of `wp_head` if an asset manifest containing valid fonts is detected. 97 | 98 | Laravel Webfonts primary functionality while in production is to provide a simple way to preload your locally hosted webfonts. 99 | 100 | This is done by reading the compiled `woff2` fonts from your Vite manifest and generating the appropriate markup for you to place inside of ``. 101 | 102 | In most cases, you can simply use the `@preloadFonts` Blade directive to handle building and echoing the font preload HTML markup. 103 | 104 | Alternatively to the Blade directive, you can access the `PreloadFonts` class directly using the `Webfonts` Facade: 105 | 106 | ```php 107 | use Log1x\LaravelWebfonts\Facades\Webfonts; 108 | 109 | // Retrieve an array of compiled font paths. 110 | $fonts = Webfonts::fonts(); 111 | 112 | // Build the font preload HTML markup. 113 | $html = Webfonts::preload()->build(); 114 | ``` 115 | 116 | Allowing/excluding certain fonts from being preloaded can be done inside `register()` of a service provider: 117 | 118 | ```php 119 | use Log1x\LaravelWebfonts\Webfonts; 120 | 121 | // Allow specific fonts. 122 | Webfonts::only(['inter-v13-latin-regular']); 123 | 124 | // Exclude specific fonts. 125 | Webfonts::except(['inter-v13-latin-500']); 126 | ``` 127 | 128 | ## Bug Reports 129 | 130 | If you discover a bug in Laravel Webfonts, please [open an issue](https://github.com/log1x/laravel-webfonts/issues). 131 | 132 | ## Contributing 133 | 134 | Contributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated. 135 | 136 | ## License 137 | 138 | Laravel Webfonts is provided under the [MIT License](LICENSE.md). 139 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "log1x/laravel-webfonts", 3 | "type": "package", 4 | "description": "Download, install, and preload over 1500 Google fonts locally in your Laravel project", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Brandon Nifong", 9 | "email": "brandon@tendency.me", 10 | "homepage": "https://github.com/log1x" 11 | } 12 | ], 13 | "autoload": { 14 | "psr-4": { 15 | "Log1x\\LaravelWebfonts\\": "src/" 16 | } 17 | }, 18 | "require": { 19 | "php": ">=8.1", 20 | "laravel/prompts": "^0.1|^0.2|^0.3", 21 | "guzzlehttp/guzzle": "^7.8" 22 | }, 23 | "require-dev": { 24 | "laravel/pint": "^1.13", 25 | "illuminate/support": "^10.0|^11.0|^12.0", 26 | "illuminate/console": "^10.0|^11.0|^12.0", 27 | "illuminate/http": "^10.0|^11.0|^12.0" 28 | }, 29 | "extra": { 30 | "laravel": { 31 | "providers": [ 32 | "Log1x\\LaravelWebfonts\\WebfontsServiceProvider" 33 | ] 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /resources/views/font-face.blade.php: -------------------------------------------------------------------------------- 1 | @props(['name', 'weight', 'style', 'path']) 2 | 3 | @font-face { 4 | font-display: swap; 5 | font-family: '{{ $name }}'; 6 | font-style: {{ $style }}; 7 | font-weight: {{ $weight }}; 8 | src: url('{{ $path }}') format('woff2'); 9 | } 10 | -------------------------------------------------------------------------------- /src/Console/Commands/WebfontsAddCommand.php: -------------------------------------------------------------------------------- 1 | option('clear-cache')) { 101 | cache()->forget($this->cache); 102 | } 103 | 104 | $this->fonts = spin( 105 | fn () => $this->fonts(), 106 | 'Fetching fonts from the Google Webfonts Helper API...' 107 | ); 108 | 109 | if ($this->fonts->isEmpty()) { 110 | $this->components->error('Unable to fetch fonts from the API.'); 111 | 112 | cache()->forget($this->cache); 113 | 114 | return; 115 | } 116 | 117 | $this->selected = multisearch( 118 | label: 'Select the fonts you would like to add to your project', 119 | options: fn (string $value) => strlen($value) > 0 ? 120 | $this->fonts 121 | ->filter(fn ($font) => Str::contains(Str::lower($font->family), Str::lower($value))) 122 | ->mapWithKeys(fn ($font) => [$font->id => $font->family]) 123 | ->all() 124 | : [], 125 | scroll: 10, 126 | placeholder: 'Inter', 127 | hint: "{$this->fonts->count()} fonts available.", 128 | required: 'You must select at least one font.', 129 | ); 130 | 131 | foreach ($this->selected as $key => $font) { 132 | $font = $this->fonts->get($font); 133 | 134 | $variants = multiselect( 135 | label: "Select the variants you would like to add to {$font->family}", 136 | options: $font->variants, 137 | scroll: 10, 138 | required: 'You must select at least one variant.', 139 | default: [$font->defVariant], 140 | ); 141 | 142 | $subsets = multiselect( 143 | label: "Select the subsets you would like to add to {$font->family}", 144 | options: $font->subsets, 145 | scroll: 10, 146 | required: 'You must select at least one subset.', 147 | default: [$font->defSubset], 148 | ); 149 | 150 | $this->selected[$key] = [ 151 | 'id' => $font->id, 152 | 'name' => $font->family, 153 | 'variants' => $variants, 154 | 'subsets' => $subsets, 155 | ]; 156 | } 157 | 158 | $selected = collect($this->selected); 159 | 160 | $this->line(" ❯ The following {$selected->count()} fonts will be added to your project:"); 161 | 162 | table( 163 | ['Name', 'Variants', 'Subsets'], 164 | $selected->map(function ($font) { 165 | $variants = Str::limit( 166 | collect($this->fonts->get($font['id'])->variants) 167 | ->filter(fn ($variant, $key) => in_array($key, $font['variants'])) 168 | ->implode(', '), 169 | 25 170 | ); 171 | 172 | $subsets = Str::limit( 173 | collect($this->fonts->get($font['id'])->subsets) 174 | ->filter(fn ($subset, $key) => in_array($key, $font['subsets'])) 175 | ->implode(', '), 176 | 25 177 | ); 178 | 179 | return [ 180 | $font['name'], 181 | $variants, 182 | $subsets, 183 | ]; 184 | })->all() 185 | ); 186 | 187 | $count = count($this->selected); 188 | $confirmed = confirm("You are about to add {$count} font(s) to your project. Do you wish to continue?"); 189 | 190 | if (! $confirmed) { 191 | return; 192 | } 193 | 194 | foreach ($this->selected as $font) { 195 | $this->line(" ❯ Adding {$font['name']} to the project..."); 196 | $this->download($font); 197 | } 198 | 199 | foreach ($this->downloaded as $name => $fonts) { 200 | $this->line(" ❯ Adding {$name} to the fonts stylesheet..."); 201 | $this->addFamily($name, $fonts); 202 | } 203 | 204 | $names = collect($this->selected)->map(fn ($font) => $this->faces || $this->downloaded ? "{$font['name']}" : "{$font['name']}"); 205 | 206 | $names = $names->count() > 1 207 | ? $names->splice(0, -1)->implode(', ').' and '.$names->last() 208 | : $names->first(); 209 | 210 | if (! $this->faces && ! $this->downloaded) { 211 | $this->components->error("Failed to add {$names} to the project."); 212 | 213 | $this->output->write("\033[1A"); 214 | 215 | return; 216 | } 217 | 218 | $names = Str::contains($names, 'and') ? "{$names} have" : "{$names} has"; 219 | 220 | $this->components->info("🎉 {$names} been successfully added to the project."); 221 | 222 | $this->output->write("\033[1A"); 223 | } 224 | 225 | /** 226 | * Add the font family to the stylesheet. 227 | * 228 | * @return void 229 | */ 230 | protected function addFamily(string $name, array $fonts) 231 | { 232 | if (! File::exists($stylesheet = $this->stylesheet())) { 233 | File::put($stylesheet, ''); 234 | } 235 | 236 | foreach ($fonts as $font) { 237 | $type = Str::of($font)->afterLast('-')->beforeLast('.')->__toString(); 238 | $weight = preg_replace('/[^0-9]/', '', $type) ?: 400; 239 | $style = Str::after($type, $weight); 240 | 241 | if (! $style || $style === 'regular') { 242 | $style = 'normal'; 243 | } 244 | 245 | $face = view('laravel-webfonts::font-face', [ 246 | 'name' => $name, 247 | 'weight' => $weight, 248 | 'style' => $style, 249 | 'path' => "../fonts/{$font}", 250 | ])->render(); 251 | 252 | if (Str::contains(File::get($stylesheet), $face)) { 253 | if ($style) { 254 | $style = Str::headline($style); 255 | } 256 | 257 | $type = $weight && $style ? "{$weight} {$style}" : ($weight ?: $style); 258 | 259 | $this->components->warn("{$name} ({$type}) already exists in the stylesheet."); 260 | 261 | continue; 262 | } 263 | 264 | $this->faces[] = $face; 265 | } 266 | 267 | if (! $this->faces) { 268 | return; 269 | } 270 | 271 | File::prepend($stylesheet, implode(PHP_EOL, $this->faces).PHP_EOL); 272 | } 273 | 274 | /** 275 | * Download the font to the project. 276 | * 277 | * @return void 278 | */ 279 | protected function download(array $font) 280 | { 281 | $response = Http::withQueryParameters([ 282 | 'download' => 'zip', 283 | 'formats' => 'woff2', 284 | 'variants' => implode(',', $font['variants']), 285 | 'subsets' => implode(',', $font['subsets']), 286 | ])->get("{$this->api}/{$font['id']}"); 287 | 288 | if ($response->failed()) { 289 | $this->components->error("Failed to download {$font['name']} to the project."); 290 | 291 | return; 292 | } 293 | 294 | File::ensureDirectoryExists($tempPath = storage_path('app/.fonts')); 295 | 296 | File::put( 297 | $tempFile = "{$tempPath}/{$font['id']}.zip", 298 | $response->body() 299 | ); 300 | 301 | $zip = new ZipArchive; 302 | $archive = $zip->open($tempFile); 303 | 304 | if ($archive !== true) { 305 | $this->components->error("Failed to unzip {$font['name']}."); 306 | 307 | return; 308 | } 309 | 310 | $zip->extractTo($tempPath = "{$tempPath}/{$font['id']}"); 311 | $zip->close(); 312 | 313 | $fileList = File::allFiles($tempPath); 314 | 315 | File::ensureDirectoryExists($path = resource_path('fonts')); 316 | 317 | $existing = collect(File::allFiles($path)) 318 | ->map(fn ($file) => $file->getFilename()) 319 | ->all(); 320 | 321 | foreach ($fileList as $file) { 322 | if (! $this->option('force') && in_array($file->getFilename(), $existing)) { 323 | $confirmed = confirm("The font {$file->getFilename()} already exists. Do you wish to overwrite it?"); 324 | 325 | if (! $confirmed) { 326 | continue; 327 | } 328 | } 329 | 330 | $this->downloaded[$font['name']][] = $file->getFilename(); 331 | 332 | File::move($file->getPathname(), "{$path}/{$file->getFilename()}"); 333 | } 334 | 335 | File::deleteDirectory($tempPath); 336 | } 337 | 338 | /** 339 | * Retrieve the fonts. 340 | * 341 | * @return \Illuminate\Support\Collection 342 | */ 343 | protected function fonts() 344 | { 345 | return cache()->remember($this->cache, $this->expiry, function () { 346 | $fonts = Http::get($this->api); 347 | 348 | if ($fonts->failed()) { 349 | return collect(); 350 | } 351 | 352 | $fonts = json_decode($fonts->body()); 353 | 354 | return collect($fonts)->mapWithKeys(function ($font) { 355 | $font->variants = collect($font->variants) 356 | ->flip() 357 | ->forget($font->defVariant) 358 | ->flip() 359 | ->prepend($font->defVariant) 360 | ->mapWithKeys(fn ($variant) => [$variant => preg_replace('/([0-9])([a-zA-Z])/', '$1 $2', Str::headline($variant))]) 361 | ->all(); 362 | 363 | $font->subsets = collect($font->subsets) 364 | ->flip() 365 | ->forget($font->defSubset) 366 | ->flip() 367 | ->prepend($font->defSubset) 368 | ->mapWithKeys(fn ($subset) => [$subset => Str::headline($subset)]) 369 | ->all(); 370 | 371 | return [$font->id => $font]; 372 | }); 373 | }); 374 | } 375 | 376 | /** 377 | * Retrieve the fonts stylesheet path. 378 | * 379 | * @return string 380 | */ 381 | protected function stylesheet() 382 | { 383 | if ($this->stylesheet) { 384 | return $this->stylesheet; 385 | } 386 | 387 | $path = resource_path($this->option('path')); 388 | $filename = $this->option('stylesheet'); 389 | 390 | if (! File::isDirectory($path)) { 391 | $path = resource_path('styles'); 392 | 393 | if (! File::isDirectory($path)) { 394 | throw new Exception('Unable to locate the styles directory.'); 395 | } 396 | } 397 | 398 | $extension = $this->option('extension') ?? collect(File::allFiles($path)) 399 | ->map(fn ($file) => $file->getExtension()) 400 | ->filter(fn ($extension) => in_array($extension, ['css', 'less', 'sass', 'scss', 'styl'])) 401 | ->first(); 402 | 403 | if (! Str::contains($filename, '.')) { 404 | $filename = "{$filename}.{$extension}"; 405 | } 406 | 407 | return $this->stylesheet = "{$path}/{$filename}"; 408 | } 409 | } 410 | -------------------------------------------------------------------------------- /src/Facades/Webfonts.php: -------------------------------------------------------------------------------- 1 | webfonts = $webfonts; 23 | } 24 | 25 | /** 26 | * Make a new instance of Preload Fonts. 27 | */ 28 | public static function make(Webfonts $webfonts): self 29 | { 30 | return new static($webfonts); 31 | } 32 | 33 | /** 34 | * Build the font preload markup. 35 | */ 36 | public function build(): ?string 37 | { 38 | if ($this->markup) { 39 | return $this->markup; 40 | } 41 | 42 | if (! $fonts = $this->webfonts()->fonts()) { 43 | return null; 44 | } 45 | 46 | return $this->markup = collect($fonts) 47 | ->map(fn ($font) => $this->asset($font)) 48 | ->map(fn ($font) => "") 49 | ->implode("\n"); 50 | } 51 | 52 | /** 53 | * Retrieve the asset URL. 54 | */ 55 | protected function asset(string $font): string 56 | { 57 | return function_exists('\Roots\asset') 58 | ? \Roots\asset($font) 59 | : asset("build/{$font}"); 60 | } 61 | 62 | /** 63 | * Retrieve the Webfonts instance. 64 | */ 65 | protected function webfonts(): Webfonts 66 | { 67 | return $this->webfonts; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Webfonts.php: -------------------------------------------------------------------------------- 1 | fonts = $this->fonts(); 45 | $this->preload = PreloadWebfonts::make($this); 46 | } 47 | 48 | /** 49 | * Make a new instance of Webfonts. 50 | */ 51 | public static function make(): self 52 | { 53 | return new static; 54 | } 55 | 56 | /** 57 | * Run the Webfonts handlers. 58 | */ 59 | public function handle(): self 60 | { 61 | $this->handleWordPress(); 62 | 63 | return $this; 64 | } 65 | 66 | /** 67 | * Retrieve the Preload Webfonts instance. 68 | */ 69 | public function preload(): PreloadWebfonts 70 | { 71 | return $this->preload; 72 | } 73 | 74 | /** 75 | * Set the fonts to exclude. 76 | */ 77 | public static function except(array $except): void 78 | { 79 | static::$except = [...static::$except, ...$except]; 80 | } 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 | 90 | /** 91 | * Retrieve the fonts from the manifest. 92 | */ 93 | public function fonts(array $except = [], array $only = []): array 94 | { 95 | if ($this->fonts) { 96 | return $this->fonts; 97 | } 98 | 99 | $except = [...static::$except, ...$except]; 100 | $only = [...static::$only, ...$only]; 101 | 102 | return collect($this->manifest()) 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)) 105 | ->reject(fn ($value, $key) => in_array(basename($key), $except) || in_array(basename($key, '.woff2'), $except)) 106 | ->all(); 107 | } 108 | 109 | /** 110 | * Handle the font preload markup for WordPress. 111 | */ 112 | protected function handleWordPress(): void 113 | { 114 | if ($this->wordpress || ! $this->isWordPress() || ! $this->fonts()) { 115 | return; 116 | } 117 | 118 | add_filter('wp_head', function () { 119 | if (! $markup = $this->preload()->build()) { 120 | return; 121 | } 122 | 123 | echo "{$markup}\n"; 124 | }, 5); 125 | 126 | $this->wordpress = true; 127 | } 128 | 129 | /** 130 | * Retrieve the asset manifest. 131 | */ 132 | protected function manifest(): array 133 | { 134 | return $this->manifest ??= $this->viteManifest(); 135 | } 136 | 137 | /** 138 | * Retrieve the Vite manifest. 139 | */ 140 | protected function viteManifest(): array 141 | { 142 | if (! file_exists($manifest = public_path('build/manifest.json'))) { 143 | return []; 144 | } 145 | 146 | $manifest = json_decode(file_get_contents($manifest), true); 147 | 148 | return collect($manifest) 149 | ->map(fn ($value, $key) => $value['file']) 150 | ->all(); 151 | } 152 | 153 | /** 154 | * Determine if the application is running WordPress. 155 | */ 156 | protected function isWordPress(): bool 157 | { 158 | return class_exists('\WP') && function_exists('\add_filter'); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/WebfontsServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton('laravel-webfonts', fn () => Webfonts::make($this->app)); 19 | } 20 | 21 | /** 22 | * Bootstrap any application services. 23 | * 24 | * @return void 25 | */ 26 | public function boot() 27 | { 28 | if ($this->app->runningInConsole()) { 29 | $this->commands(WebfontsAddCommand::class); 30 | } 31 | 32 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-webfonts'); 33 | 34 | Blade::directive('preloadFonts', fn () => "preload()->build(); ?>"); 35 | 36 | $this->app->make('laravel-webfonts')->handle(); 37 | } 38 | } 39 | --------------------------------------------------------------------------------