Icon-System: icon()-Helper, lokale Bootstrap-Icons, icons-add.php
Inline-SVG-Ausgabe via icon('name', 'klasse', 'label?') aus
public/assets/icons/. Dekorativ (aria-hidden) oder semantisch (role=img).
.icon-Basisklasse in utilities.css (1em, currentColor). bin/icons-add.php
holt neue Icons einzeln von icons.getbootstrap.com.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KDQZ6FuchNUh2bxSW9PeNv
This commit is contained in:
61
bin/icons-add.php
Normal file
61
bin/icons-add.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Bootstrap Icons (MIT) lokal nachladen — holt einzelne Icon-SVGs und legt sie
|
||||
* minimiert unter public/assets/icons/<name>.svg ab (nur viewBox + Pfade,
|
||||
* Größe/Farbe steuert CSS über die .icon-Klasse bzw. currentColor).
|
||||
*
|
||||
* NUR CLI/Build — nie im Request-Pfad. Besucher laden ausschließlich die lokalen
|
||||
* SVGs (inline via icon()-Helper), niemals ein CDN.
|
||||
*
|
||||
* Aufruf: php bin/icons-add.php pause-fill play-fill arrow-right ...
|
||||
* Icon-Namen siehe https://icons.getbootstrap.com (Dateiname ohne .svg).
|
||||
*/
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require dirname(__DIR__) . '/app/bootstrap.php';
|
||||
|
||||
const BI_VERSION = '1.11.3';
|
||||
const BI_BASE = 'https://cdn.jsdelivr.net/npm/bootstrap-icons@' . BI_VERSION . '/icons/';
|
||||
|
||||
$names = array_slice($argv, 1);
|
||||
if ($names === []) {
|
||||
fwrite(STDERR, "Usage: php bin/icons-add.php <icon-name> [<icon-name> ...]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$dir = PUBLIC_PATH . '/assets/icons';
|
||||
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) {
|
||||
fwrite(STDERR, "Kann Verzeichnis nicht anlegen: {$dir}\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$failed = 0;
|
||||
foreach ($names as $name) {
|
||||
$name = basename(trim($name));
|
||||
if ($name === '' || !preg_match('/^[a-z0-9-]+$/', $name)) {
|
||||
fwrite(STDERR, "Übersprungen (ungültiger Name): {$name}\n");
|
||||
$failed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$raw = @file_get_contents(BI_BASE . $name . '.svg');
|
||||
if ($raw === false || !str_contains($raw, '<svg')) {
|
||||
fwrite(STDERR, "Nicht gefunden: {$name}\n");
|
||||
$failed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Inneres SVG extrahieren und minimal neu aufbauen (currentColor erbt).
|
||||
$inner = preg_replace(['/.*?<svg[^>]*>/s', '#</svg>\s*$#s'], '', $raw);
|
||||
$svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">' . trim((string) $inner) . '</svg>' . "\n";
|
||||
|
||||
file_put_contents($dir . '/' . $name . '.svg', $svg);
|
||||
echo "✓ {$name}\n";
|
||||
}
|
||||
|
||||
exit($failed > 0 ? 1 : 0);
|
||||
Reference in New Issue
Block a user