From d42217fd209a1f664ea05784578fd862e2fad0e7 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Tue, 10 Mar 2026 08:21:06 +0100 Subject: [PATCH] =?UTF-8?q?Refactor:=20config=20Kirby=20scind=C3=A9e=20en?= =?UTF-8?q?=20menu.php=20+=20thumbs.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - menu.php: helper menuItem() — détection active mutualisée - thumbs.php: helpers srcsetPreset/srcsetPair — widths définis une seule fois, paires normal/webp générées automatiquement sans duplication - config.php: réduit à l'essentiel via require Co-Authored-By: Claude Sonnet 4.6 --- site/config/config.php | 143 +++-------------------------------------- site/config/menu.php | 36 +++++++++++ site/config/thumbs.php | 54 ++++++++++++++++ 3 files changed, 98 insertions(+), 135 deletions(-) create mode 100644 site/config/menu.php create mode 100644 site/config/thumbs.php diff --git a/site/config/config.php b/site/config/config.php index 847111c..c556463 100644 --- a/site/config/config.php +++ b/site/config/config.php @@ -1,141 +1,14 @@ true, - - // Panel configuration - 'panel' => [ - 'css' => 'assets/css/custom-panel.css', - 'theme' => 'dark', - // Menu personnalisé du panel - 'menu' => [ - 'site' => [ - 'label' => 'Données partagées', - 'icon' => 'cog', - 'current' => function (string $current): bool { - $path = Kirby\Cms\App::instance()->path(); - return Str::contains($path, '/site'); - } - ], - '-', // Séparateur - 'home' => [ - 'label' => 'Accueil', - 'icon' => 'home', - 'link' => 'pages/home', - 'current' => function (string $current): bool { - $path = Kirby\Cms\App::instance()->path(); - return Str::contains($path, 'pages/home'); - } - ], - 'expertise' => [ - 'label' => 'Expertise', - 'icon' => 'wand', - 'link' => 'pages/expertise', - 'current' => function (string $current): bool { - $path = Kirby\Cms\App::instance()->path(); - return Str::contains($path, 'pages/expertise'); - } - ], - 'portfolio' => [ - 'label' => 'Portfolio', - 'icon' => 'images', - 'link' => 'pages/portfolio', - 'current' => function (string $current): bool { - $path = Kirby\Cms\App::instance()->path(); - return Str::contains($path, 'pages/portfolio'); - } - ], - 'jouer' => [ - 'label' => 'Jouer', - 'icon' => 'play', - 'link' => 'pages/jouer', - 'current' => function (string $current): bool { - $path = Kirby\Cms\App::instance()->path(); - return Str::contains($path, 'pages/jouer'); - } - ], - 'a-propos' => [ - 'label' => 'À propos', - 'icon' => 'users', - 'link' => 'pages/a-propos', - 'current' => function (string $current): bool { - $path = Kirby\Cms\App::instance()->path(); - return Str::contains($path, 'pages/a-propos'); - } - ], - 'blog' => [ - 'label' => 'Blog', - 'icon' => 'text', - 'link' => 'pages/blog', - 'current' => function (string $current): bool { - $path = Kirby\Cms\App::instance()->path(); - return Str::contains($path, 'pages/blog'); - } - ], - '-', // Séparateur - 'users', - 'system' - ] - ], - - // Langues + 'debug' => true, 'languages' => true, - // Thumbs - 'thumbs' => [ - 'quality' => 80, - 'srcsets' => [ - 'default' => [ - '300w' => ['width' => 300], - '600w' => ['width' => 600], - '900w' => ['width' => 900], - '1200w' => ['width' => 1200], - ], - // Galerie portfolio — desktop ~15vw, mobile ~33vw (3 colonnes) - // Widths couvrent 1x et 2x retina pour les deux breakpoints - 'gallery' => [ - '200w' => ['width' => 200], - '300w' => ['width' => 300], - '400w' => ['width' => 400], - '600w' => ['width' => 600], - '800w' => ['width' => 800], - ], - 'gallery-webp' => [ - '200w' => ['width' => 200, 'format' => 'webp'], - '300w' => ['width' => 300, 'format' => 'webp'], - '400w' => ['width' => 400, 'format' => 'webp'], - '600w' => ['width' => 600, 'format' => 'webp'], - '800w' => ['width' => 800, 'format' => 'webp'], - ], - // Mockup portfolio — desktop ~25vw, mobile ~90vw - 'mockup' => [ - '350w' => ['width' => 350], - '480w' => ['width' => 480], - '700w' => ['width' => 700], - '960w' => ['width' => 960], - ], - 'mockup-webp' => [ - '350w' => ['width' => 350, 'format' => 'webp'], - '480w' => ['width' => 480, 'format' => 'webp'], - '700w' => ['width' => 700, 'format' => 'webp'], - '960w' => ['width' => 960, 'format' => 'webp'], - ], - // Vignettes jeux — active: clamp(170px, 18.41vw, 355px), retina 2x → 710px - 'thumbnail' => [ - '170w' => ['width' => 170], - '255w' => ['width' => 255], - '355w' => ['width' => 355], - '510w' => ['width' => 510], - '710w' => ['width' => 710], - ], - 'thumbnail-webp' => [ - '170w' => ['width' => 170, 'format' => 'webp'], - '255w' => ['width' => 255, 'format' => 'webp'], - '355w' => ['width' => 355, 'format' => 'webp'], - '510w' => ['width' => 510, 'format' => 'webp'], - '710w' => ['width' => 710, 'format' => 'webp'], - ], - ], + 'panel' => [ + 'css' => 'assets/css/custom-panel.css', + 'theme' => 'dark', + 'menu' => require __DIR__ . '/menu.php', ], -]; \ No newline at end of file + + 'thumbs' => require __DIR__ . '/thumbs.php', +]; diff --git a/site/config/menu.php b/site/config/menu.php new file mode 100644 index 0000000..ab988d0 --- /dev/null +++ b/site/config/menu.php @@ -0,0 +1,36 @@ + $label, + 'icon' => $icon, + 'link' => $link, + 'current' => function () use ($link): bool { + return Str::contains(Kirby\Cms\App::instance()->path(), $link); + }, + ]; +} + +return [ + 'site' => [ + 'label' => 'Données partagées', + 'icon' => 'cog', + 'current' => function (): bool { + return Str::contains(Kirby\Cms\App::instance()->path(), '/site'); + }, + ], + '-', + 'home' => menuItem('home', 'Accueil', 'home', 'pages/home'), + 'expertise' => menuItem('expertise', 'Expertise','wand', 'pages/expertise'), + 'portfolio' => menuItem('portfolio', 'Portfolio','images', 'pages/portfolio'), + 'jouer' => menuItem('jouer', 'Jouer', 'play', 'pages/jouer'), + 'a-propos' => menuItem('a-propos', 'À propos', 'users', 'pages/a-propos'), + 'blog' => menuItem('blog', 'Blog', 'text', 'pages/blog'), + '-', + 'users', + 'system', +]; diff --git a/site/config/thumbs.php b/site/config/thumbs.php new file mode 100644 index 0000000..8d0c22a --- /dev/null +++ b/site/config/thumbs.php @@ -0,0 +1,54 @@ + largeur_px]. + * Applique le multiplicateur et optionnellement un format (ex: 'webp'). + */ +function srcsetPreset(array $widths, float $mult, ?string $format = null): array +{ + $preset = []; + foreach ($widths as $label => $px) { + $entry = ['width' => (int) round($px * $mult)]; + if ($format !== null) { + $entry['format'] = $format; + } + $preset[$label] = $entry; + } + return $preset; +} + +/** + * Génère une paire de presets (original + webp) depuis un tableau de widths. + * Retourne ['name' => [...], 'name-webp' => [...]]. + */ +function srcsetPair(string $name, array $widths, float $mult): array +{ + return [ + $name => srcsetPreset($widths, $mult), + $name . '-webp' => srcsetPreset($widths, $mult, 'webp'), + ]; +} + +// Multiplicateur global (ex: 1.5 pour avoir de la marge sur les écrans Retina) +$m = 1.5; + +// Définition des widths par usage (une seule fois) +$widths = [ + 'default' => ['300w' => 300, '600w' => 600, '900w' => 900, '1200w' => 1200], + // Galerie portfolio — desktop ~15vw, mobile ~33vw (3 colonnes) + 'gallery' => ['200w' => 200, '300w' => 300, '400w' => 400, '600w' => 600, '800w' => 800], + // Mockup portfolio — desktop ~25vw, mobile ~90vw + 'mockup' => ['350w' => 350, '480w' => 480, '700w' => 700, '960w' => 960], + // Vignettes jeux — active: clamp(170px, 18.41vw, 355px) + 'thumbnail' => ['170w' => 170, '255w' => 255, '355w' => 355, '510w' => 510, '710w' => 710], +]; + +return [ + 'quality' => 80, + 'srcsets' => array_merge( + ['default' => srcsetPreset($widths['default'], $m)], + srcsetPair('gallery', $widths['gallery'], $m), + srcsetPair('mockup', $widths['mockup'], $m), + srcsetPair('thumbnail', $widths['thumbnail'], $m), + ), +];