Refactor: config Kirby scindée en menu.php + thumbs.php
All checks were successful
Deploy / Deploy to Production (push) Successful in 17s
All checks were successful
Deploy / Deploy to Production (push) Successful in 17s
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
0ea4bfe539
commit
d42217fd20
3 changed files with 98 additions and 135 deletions
54
site/config/thumbs.php
Normal file
54
site/config/thumbs.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Génère un preset srcset Kirby à partir d'un tableau [label => 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),
|
||||
),
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue