home > controller : shuffle slides + déplacer logique depuis template
All checks were successful
Deploy / Deploy to Production (push) Successful in 3s
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:
parent
06fc040f80
commit
5d6fa47606
6 changed files with 102 additions and 80 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
33
site/controllers/home.php
Normal file
33
site/controllers/home.php
Normal 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,
|
||||
];
|
||||
};
|
||||
|
|
@ -1,26 +1,26 @@
|
|||
<?php
|
||||
|
||||
return function($page) {
|
||||
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 {
|
||||
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 !== '');
|
||||
|
|
|
|||
|
|
@ -1,29 +1,6 @@
|
|||
<?php snippet('header') ?>
|
||||
|
||||
<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 if ($slide['pair']): ?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue