@php // « Selected works » is auto-populated from the gallery: the first N // published projects (in the order arranged on /gallery), shown by their // cover, each tile linking to its article. N comes from the gallery // settings (admin → Réalisations → ⚙ Réglages). With no project yet, we // fall back to the developer placeholder images so the home stays nice. $count = \App\Support\GallerySettings::homeSelectedCount(); // Filter out projects with no usable cover BEFORE applying the count, so // « show N » really shows N when N covered projects exist. $tiles = \App\Models\Project::where('status', 'published') ->orderBy('sort')->orderBy('id') ->get(['id', 'slug', 'title', 'cover']) ->map(fn ($p) => ['img' => media_url($p->cover), 'href' => '/gallery/' . $p->slug, 'label' => $p->title]) ->filter(fn ($t) => $t['img'] !== '') ->take($count) ->values(); if ($tiles->isEmpty()) { $tiles = collect(range(1, 9)) ->map(fn ($i) => ['img' => media_url($block->get('image_' . $i)), 'href' => null, 'label' => null]) ->filter(fn ($t) => $t['img'] !== '') ->values(); } // Spread the tiles round-robin across UP TO 3 parallax columns. With only // 1–2 tiles we use that many columns (centered, capped width) so the mosaic // never leaves blank thirds. With ≥3 tiles it's the full 3-column grid // (byte-identical to the original markup). $usedCols = min(3, max(1, $tiles->count())); $cols = array_fill(0, $usedCols, []); foreach ($tiles as $i => $tile) { $cols[$i % $usedCols][] = $tile + ['ratio' => $i % 2 === 0 ? '3/4' : '4/5']; } $colMeta = [ ['class' => 'gallery-col', 'parallax' => '0.12'], ['class' => 'gallery-col gallery-col-offset', 'parallax' => '-0.08'], ['class' => 'gallery-col', 'parallax' => '0.18'], ]; $gridStyle = $usedCols < 3 ? ' style="grid-template-columns: repeat(' . $usedCols . ', 1fr); max-width: ' . ($usedCols === 1 ? '520px' : '880px') . ';"' : ''; @endphp