From 5d6fa476062895a9885eb556aa4b0ad07e81de36 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Fri, 5 Jun 2026 16:35:08 +0200 Subject: [PATCH] =?UTF-8?q?home=20>=20controller=20:=20shuffle=20slides=20?= =?UTF-8?q?+=20d=C3=A9placer=20logique=20depuis=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- site/blueprints/pages/index.yml | 1 + site/blueprints/pages/project.yml | 90 ++++++++++++++++--------------- site/blueprints/site.yml | 7 +++ site/controllers/home.php | 33 ++++++++++++ site/controllers/index.php | 28 +++++----- site/templates/home.php | 23 -------- 6 files changed, 102 insertions(+), 80 deletions(-) create mode 100644 site/controllers/home.php diff --git a/site/blueprints/pages/index.yml b/site/blueprints/pages/index.yml index 370bc58..ce4e703 100644 --- a/site/blueprints/pages/index.yml +++ b/site/blueprints/pages/index.yml @@ -22,6 +22,7 @@ tabs: size: huge info: "{{ page.category }}, {{ page.date.toDate('Y') }}" sortBy: date desc + limit: 100 image: ratio: 12/9 back: white diff --git a/site/blueprints/pages/project.yml b/site/blueprints/pages/project.yml index 48f033e..c9c526e 100644 --- a/site/blueprints/pages/project.yml +++ b/site/blueprints/pages/project.yml @@ -1,43 +1,47 @@ -columns: - - width: 1/3 - fields: - shownTitle: - label: Titre affiché - type: writer - help: Le titre à afficher (il est possible de mettre le titre ou une partie en italique ou en exposant en sélectionnat du texte) - marks: - - italic - - sup - nodes: false - category: - label: Catégorie - type: tags - icon: folder - help: Sélectionner une ou plusieurs catégories, ou en créer de nouvelles - options: - type: query - query: page.siblings.pluck("category", ",", true) - date: - label: Date - type: date - tags: - label: Tags - type: tags - help: Sélectionner un ou plusieurs tags, ou en créer de nouveaux - options: - type: query - query: page.siblings.pluck("tags", ",", true) - - width: 2/3 - fields: - slideshow: - type: files - min: 1 - layout: cardlets - image: - ratio: 16/9 - back: transparent - uploads: - template: slideshow-files - description: - label: Description - type: writer +tabs: + contentTab: + label: Contenu + columns: + - width: 1/3 + fields: + shownTitle: + label: Titre affiché + type: writer + help: Le titre à afficher (il est possible de mettre le titre ou une partie en italique ou en exposant en sélectionnat du texte) + marks: + - italic + - sup + nodes: false + category: + label: Catégorie + type: tags + icon: folder + help: Sélectionner une ou plusieurs catégories, ou en créer de nouvelles + options: + type: query + query: page.parent.childrenAndDrafts.pluck("category", ",", true) + date: + label: Date + type: date + tags: + label: Tags + type: tags + help: Sélectionner un ou plusieurs tags, ou en créer de nouveaux + options: + type: query + query: page.parent.childrenAndDrafts.pluck("tags", ",", true) + - width: 2/3 + fields: + slideshow: + type: files + min: 1 + layout: cardlets + image: + ratio: 16/9 + back: transparent + uploads: + template: slideshow-files + description: + label: Description + type: writer + files: tabs/files diff --git a/site/blueprints/site.yml b/site/blueprints/site.yml index ef3d80f..57f184f 100644 --- a/site/blueprints/site.yml +++ b/site/blueprints/site.yml @@ -2,6 +2,13 @@ title: Site tabs: content: 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: type: files label: Carroussel diff --git a/site/controllers/home.php b/site/controllers/home.php new file mode 100644 index 0000000..9ea40d6 --- /dev/null +++ b/site/controllers/home.php @@ -0,0 +1,33 @@ +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, + ]; +}; diff --git a/site/controllers/index.php b/site/controllers/index.php index e0efd7b..e8c146a 100644 --- a/site/controllers/index.php +++ b/site/controllers/index.php @@ -1,26 +1,26 @@ $value) { - if (is_array($value)) { - $result = array_merge($result, array_flatten($value)); - } else { + function array_flatten($array) { + if (!is_array($array)) { + return false; + } + $result = array(); + foreach ($array as $key => $value) { + if (is_array($value)) { + $result = array_merge($result, array_flatten($value)); + } else { $result = array_merge($result, array($key => $value)); - } - } - return $result; + } + } + return $result; } - + function getSingleCategories($pages) { $categoriesRawFields = $pages->pluck('category'); // return ["A, B, C", "A, B"] $splittedCategoriesFields = array_map(function($field) { return explode(',', $field); - }, $categoriesRawFields); // return ’[["A", "B", "C",], ["A", "B"]] + }, $categoriesRawFields); // return '[["A", "B", "C",], ["A", "B"]] $flattenedCategories = array_flatten($splittedCategoriesFields); $trimmed = array_map('trim', $flattenedCategories); $filtered = array_filter($trimmed, fn($v) => $v !== ''); diff --git a/site/templates/home.php b/site/templates/home.php index 868dbd3..f72425a 100644 --- a/site/templates/home.php +++ b/site/templates/home.php @@ -1,29 +1,6 @@
- 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++; - } - } - ?>