neues Admin UI Layout eingeführt. Alle Tests auf den neusten Stand gebracht.
This commit is contained in:
@@ -12,7 +12,7 @@ use Illuminate\Support\Str;
|
||||
|
||||
class SyncGoogleFonts extends Command
|
||||
{
|
||||
protected $signature = 'fonts:sync-google {--count=50 : Number of popular fonts to fetch} {--weights=400,700 : Comma separated numeric font weights to download} {--italic : Also download italic variants where available} {--force : Re-download files even if they exist} {--path= : Optional custom output directory (defaults to public/fonts/google)} {--family= : Download a single family by name (case-insensitive)} {--category= : Filter by category, comma separated (e.g. sans-serif,serif)} {--dry-run : Show what would be downloaded without writing files}';
|
||||
protected $signature = 'fonts:sync-google {--count=50 : Number of popular fonts to fetch} {--weights=400,700 : Comma separated numeric font weights to download} {--italic : Also download italic variants where available} {--force : Re-download files even if they exist} {--path= : Optional custom output directory (defaults to public/fonts/google)} {--family= : Download specific family name(s), comma separated (case-insensitive)} {--category= : Filter by category, comma separated (e.g. sans-serif,serif)} {--prune : Remove local font families not included in this sync} {--dry-run : Show what would be downloaded without writing files}';
|
||||
|
||||
protected $description = 'Download the most popular Google Fonts to the local public/fonts/google directory and generate a manifest + CSS file.';
|
||||
|
||||
@@ -33,16 +33,18 @@ class SyncGoogleFonts extends Command
|
||||
$includeItalic = (bool) $this->option('italic');
|
||||
$force = (bool) $this->option('force');
|
||||
$dryRun = (bool) $this->option('dry-run');
|
||||
$familyOption = $this->normalizeFamilyOption($this->option('family'));
|
||||
$families = $this->normalizeFamilyOption($this->option('family'));
|
||||
$categories = $this->prepareCategories($this->option('category'));
|
||||
$prune = (bool) $this->option('prune');
|
||||
|
||||
$pathOption = $this->option('path');
|
||||
$basePath = $pathOption
|
||||
? (Str::startsWith($pathOption, DIRECTORY_SEPARATOR) ? $pathOption : base_path($pathOption))
|
||||
: public_path('fonts/google');
|
||||
|
||||
if ($familyOption) {
|
||||
$this->info(sprintf('Fetching Google Font family "%s" (weights: %s, italic: %s)...', $familyOption, implode(', ', $weights), $includeItalic ? 'yes' : 'no'));
|
||||
if (count($families)) {
|
||||
$label = count($families) > 1 ? 'families' : 'family';
|
||||
$this->info(sprintf('Fetching Google Font %s "%s" (weights: %s, italic: %s)...', $label, implode(', ', $families), implode(', ', $weights), $includeItalic ? 'yes' : 'no'));
|
||||
} else {
|
||||
$this->info(sprintf('Fetching top %d Google Fonts (weights: %s, italic: %s)...', $count, implode(', ', $weights), $includeItalic ? 'yes' : 'no'));
|
||||
}
|
||||
@@ -75,12 +77,27 @@ class SyncGoogleFonts extends Command
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$items = $this->filterFonts($items, $familyOption, $categories);
|
||||
$items = $this->filterFonts($items, $families, $categories);
|
||||
|
||||
if ($familyOption && ! count($items)) {
|
||||
$this->error(sprintf('Font family "%s" was not found.', $familyOption));
|
||||
if (count($families)) {
|
||||
$matchedFamilies = collect($items)
|
||||
->pluck('family')
|
||||
->filter()
|
||||
->map(fn ($family) => strtolower((string) $family))
|
||||
->unique()
|
||||
->all();
|
||||
|
||||
return self::FAILURE;
|
||||
$missingFamilies = collect($families)
|
||||
->filter(fn ($family) => ! in_array(strtolower($family), $matchedFamilies, true))
|
||||
->values()
|
||||
->all();
|
||||
|
||||
if (count($missingFamilies)) {
|
||||
$label = count($missingFamilies) > 1 ? 'families' : 'family';
|
||||
$this->error(sprintf('Font %s not found: %s.', $label, implode(', ', $missingFamilies)));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (! count($items)) {
|
||||
@@ -89,7 +106,7 @@ class SyncGoogleFonts extends Command
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$selected = $familyOption ? $items : array_slice($items, 0, $count);
|
||||
$selected = count($families) ? $items : array_slice($items, 0, $count);
|
||||
$manifestFonts = [];
|
||||
$filesystem = new Filesystem;
|
||||
|
||||
@@ -170,21 +187,41 @@ class SyncGoogleFonts extends Command
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->pruneStaleFamilies($basePath, $manifestFonts);
|
||||
$this->writeManifest($basePath, $manifestFonts);
|
||||
$this->writeCss($basePath, $manifestFonts);
|
||||
$finalFonts = $manifestFonts;
|
||||
if (count($families) && ! $prune) {
|
||||
$existingFonts = $this->loadExistingManifestFonts($basePath);
|
||||
$finalFonts = $this->mergeManifestFonts($existingFonts, $manifestFonts);
|
||||
}
|
||||
|
||||
if ($prune || ! count($families)) {
|
||||
$this->pruneStaleFamilies($basePath, $finalFonts);
|
||||
}
|
||||
|
||||
$this->writeManifest($basePath, $finalFonts);
|
||||
$this->writeCss($basePath, $finalFonts);
|
||||
Cache::forget('fonts:manifest');
|
||||
|
||||
$this->info(sprintf('Synced %d font families to %s', count($manifestFonts), $basePath));
|
||||
$this->info(sprintf('Synced %d font families to %s', count($finalFonts), $basePath));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function normalizeFamilyOption(?string $family): ?string
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function normalizeFamilyOption(?string $family): array
|
||||
{
|
||||
$family = trim((string) $family);
|
||||
if ($family === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $family !== '' ? $family : null;
|
||||
$parts = array_filter(array_map('trim', explode(',', $family)));
|
||||
|
||||
return collect($parts)
|
||||
->unique(fn ($value) => strtolower((string) $value))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,9 +240,10 @@ class SyncGoogleFonts extends Command
|
||||
|
||||
/**
|
||||
* @param array<int, mixed> $items
|
||||
* @param array<int, string> $families
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
private function filterFonts(array $items, ?string $family, array $categories): array
|
||||
private function filterFonts(array $items, array $families, array $categories): array
|
||||
{
|
||||
$filtered = collect($items)
|
||||
->filter(fn ($font) => is_array($font) && isset($font['family']))
|
||||
@@ -219,9 +257,13 @@ class SyncGoogleFonts extends Command
|
||||
return in_array($category, $categories, true);
|
||||
});
|
||||
|
||||
if ($family) {
|
||||
$filtered = $filtered->filter(function ($font) use ($family) {
|
||||
return strcasecmp((string) $font['family'], $family) === 0;
|
||||
if (count($families)) {
|
||||
$normalizedFamilies = collect($families)
|
||||
->map(fn ($family) => strtolower((string) $family))
|
||||
->all();
|
||||
|
||||
$filtered = $filtered->filter(function ($font) use ($normalizedFamilies) {
|
||||
return in_array(strtolower((string) $font['family']), $normalizedFamilies, true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -291,6 +333,49 @@ class SyncGoogleFonts extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
private function loadExistingManifestFonts(string $basePath): array
|
||||
{
|
||||
$manifestPath = $basePath.'/manifest.json';
|
||||
if (! File::exists($manifestPath)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$manifest = json_decode(File::get($manifestPath), true);
|
||||
if (! is_array($manifest)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$fonts = $manifest['fonts'] ?? [];
|
||||
|
||||
return is_array($fonts) ? $fonts : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, mixed> $existing
|
||||
* @param array<int, mixed> $incoming
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
private function mergeManifestFonts(array $existing, array $incoming): array
|
||||
{
|
||||
$merged = collect($existing)
|
||||
->filter(fn ($font) => is_array($font) && isset($font['family']))
|
||||
->keyBy(fn ($font) => strtolower((string) $font['family']))
|
||||
->all();
|
||||
|
||||
foreach ($incoming as $font) {
|
||||
if (! is_array($font) || ! isset($font['family'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$merged[strtolower((string) $font['family'])] = $font;
|
||||
}
|
||||
|
||||
return array_values($merged);
|
||||
}
|
||||
|
||||
private function writeManifest(string $basePath, array $fonts): void
|
||||
{
|
||||
$manifest = [
|
||||
|
||||
Reference in New Issue
Block a user