home > controller : shuffle slides + déplacer logique depuis template
All checks were successful
Deploy / Deploy to Production (push) Successful in 3s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2026-06-05 16:35:08 +02:00
parent 06fc040f80
commit 5d6fa47606
6 changed files with 102 additions and 80 deletions

View file

@ -22,6 +22,7 @@ tabs:
size: huge size: huge
info: "{{ page.category }}, {{ page.date.toDate('Y') }}" info: "{{ page.category }}, {{ page.date.toDate('Y') }}"
sortBy: date desc sortBy: date desc
limit: 100
image: image:
ratio: 12/9 ratio: 12/9
back: white back: white

View file

@ -1,43 +1,47 @@
columns: tabs:
- width: 1/3 contentTab:
fields: label: Contenu
shownTitle: columns:
label: Titre affiché - width: 1/3
type: writer fields:
help: Le titre à afficher (il est possible de mettre le titre ou une partie en italique ou en exposant en sélectionnat du texte) shownTitle:
marks: label: Titre affiché
- italic type: writer
- sup help: Le titre à afficher (il est possible de mettre le titre ou une partie en italique ou en exposant en sélectionnat du texte)
nodes: false marks:
category: - italic
label: Catégorie - sup
type: tags nodes: false
icon: folder category:
help: Sélectionner une ou plusieurs catégories, ou en créer de nouvelles label: Catégorie
options: type: tags
type: query icon: folder
query: page.siblings.pluck("category", ",", true) help: Sélectionner une ou plusieurs catégories, ou en créer de nouvelles
date: options:
label: Date type: query
type: date query: page.parent.childrenAndDrafts.pluck("category", ",", true)
tags: date:
label: Tags label: Date
type: tags type: date
help: Sélectionner un ou plusieurs tags, ou en créer de nouveaux tags:
options: label: Tags
type: query type: tags
query: page.siblings.pluck("tags", ",", true) help: Sélectionner un ou plusieurs tags, ou en créer de nouveaux
- width: 2/3 options:
fields: type: query
slideshow: query: page.parent.childrenAndDrafts.pluck("tags", ",", true)
type: files - width: 2/3
min: 1 fields:
layout: cardlets slideshow:
image: type: files
ratio: 16/9 min: 1
back: transparent layout: cardlets
uploads: image:
template: slideshow-files ratio: 16/9
description: back: transparent
label: Description uploads:
type: writer template: slideshow-files
description:
label: Description
type: writer
files: tabs/files

View file

@ -2,6 +2,13 @@ title: Site
tabs: tabs:
content: content:
fields: fields:
areSlidesShuffled:
label: Mélanger aléatoirement
type: toggle
width: 1/3
help: |
Ordonne aléatoirement les slides en front.
Deux images verticales successives dans le panel restent dans la même slide en front.
slideshow: slideshow:
type: files type: files
label: Carroussel label: Carroussel

33
site/controllers/home.php Normal file
View file

@ -0,0 +1,33 @@
<?php
return function($site) {
$files = $site->slideshow()->toFiles();
$count = $files->count();
$units = [];
$i = 0;
while ($i < $count) {
$file = $files->nth($i);
$nextFile = $files->nth($i + 1);
$isPortrait = $file->type() === 'image' && $file->orientation() === 'portrait';
$nextIsPortrait = $nextFile && $nextFile->type() === 'image' && $nextFile->orientation() === 'portrait';
if ($isPortrait && $nextIsPortrait) {
$units[] = ['pair' => true, 'a' => $file, 'b' => $nextFile];
$i += 2;
} else {
$units[] = ['pair' => false, 'file' => $file];
$i++;
}
}
if ($site->areSlidesShuffled()->isTrue()) {
shuffle($units);
}
return [
'slides' => $units,
];
};

View file

@ -1,26 +1,26 @@
<?php <?php
return function($page) { return function($page) {
function array_flatten($array) { function array_flatten($array) {
if (!is_array($array)) { if (!is_array($array)) {
return false; return false;
} }
$result = array(); $result = array();
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if (is_array($value)) { if (is_array($value)) {
$result = array_merge($result, array_flatten($value)); $result = array_merge($result, array_flatten($value));
} else { } else {
$result = array_merge($result, array($key => $value)); $result = array_merge($result, array($key => $value));
} }
} }
return $result; return $result;
} }
function getSingleCategories($pages) { function getSingleCategories($pages) {
$categoriesRawFields = $pages->pluck('category'); // return ["A, B, C", "A, B"] $categoriesRawFields = $pages->pluck('category'); // return ["A, B, C", "A, B"]
$splittedCategoriesFields = array_map(function($field) { $splittedCategoriesFields = array_map(function($field) {
return explode(',', $field); return explode(',', $field);
}, $categoriesRawFields); // return [["A", "B", "C",], ["A", "B"]] }, $categoriesRawFields); // return '[["A", "B", "C",], ["A", "B"]]
$flattenedCategories = array_flatten($splittedCategoriesFields); $flattenedCategories = array_flatten($splittedCategoriesFields);
$trimmed = array_map('trim', $flattenedCategories); $trimmed = array_map('trim', $flattenedCategories);
$filtered = array_filter($trimmed, fn($v) => $v !== ''); $filtered = array_filter($trimmed, fn($v) => $v !== '');

View file

@ -1,29 +1,6 @@
<?php snippet('header') ?> <?php snippet('header') ?>
<div id="home-slideshow"> <div id="home-slideshow">
<?php
$files = $site->slideshow()->toFiles();
$count = $files->count();
$slides = [];
$i = 0;
while ($i < $count) {
$file = $files->nth($i);
$nextFile = $files->nth($i + 1);
$isPortrait = $file->type() === 'image' && $file->orientation() === 'portrait';
$nextIsPortrait = $nextFile && $nextFile->type() === 'image' && $nextFile->orientation() === 'portrait';
if ($isPortrait && $nextIsPortrait) {
$slides[] = ['pair' => true, 'a' => $file, 'b' => $nextFile];
$i += 2;
} else {
$slides[] = ['pair' => false, 'file' => $file];
$i++;
}
}
?>
<?php foreach ($slides as $slide): ?> <?php foreach ($slides as $slide): ?>
<?php if ($slide['pair']): ?> <?php if ($slide['pair']): ?>