home > slideshow fix sorting
All checks were successful
Deploy / Deploy to Production (push) Successful in 2s
All checks were successful
Deploy / Deploy to Production (push) Successful in 2s
This commit is contained in:
parent
47e30e8d61
commit
9670680802
1 changed files with 29 additions and 20 deletions
|
|
@ -2,39 +2,48 @@
|
|||
|
||||
<div id="home-slideshow">
|
||||
<?php
|
||||
$files = array_values($site->files()->sortBy('sort')->data());
|
||||
$count = count($files);
|
||||
$i = 0;
|
||||
while ($i < $count):
|
||||
$file = $files[$i];
|
||||
$nextFile = $files[$i + 1] ?? null;
|
||||
$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 if ($isPortrait && $nextIsPortrait): ?>
|
||||
<?php foreach ($slides as $slide): ?>
|
||||
<?php if ($slide['pair']): ?>
|
||||
<div class="slide portrait-pair">
|
||||
<?php snippet('picture', ['file' => $file, 'srcsetName' => 'home-slideshow', 'sizes' => '50vw', 'lazy' => false]) ?>
|
||||
<?php snippet('picture', ['file' => $nextFile, 'srcsetName' => 'home-slideshow', 'sizes' => '50vw', 'lazy' => false]) ?>
|
||||
<?php snippet('picture', ['file' => $slide['a'], 'srcsetName' => 'home-slideshow', 'sizes' => '50vw', 'lazy' => false]) ?>
|
||||
<?php snippet('picture', ['file' => $slide['b'], 'srcsetName' => 'home-slideshow', 'sizes' => '50vw', 'lazy' => false]) ?>
|
||||
</div>
|
||||
<?php $i += 2 ?>
|
||||
|
||||
<?php elseif ($file->type() === 'video'): ?>
|
||||
<?php elseif ($slide['file']->type() === 'video'): ?>
|
||||
<div class="slide">
|
||||
<video autoplay muted loop playsinline data-id="<?= $file->uuid() ?>">
|
||||
<source src="<?= $file->url() ?>" type="<?= $file->mime() ?>">
|
||||
<video autoplay muted loop playsinline data-id="<?= $slide['file']->uuid() ?>">
|
||||
<source src="<?= $slide['file']->url() ?>" type="<?= $slide['file']->mime() ?>">
|
||||
</video>
|
||||
</div>
|
||||
<?php $i++ ?>
|
||||
|
||||
<?php else: ?>
|
||||
<div class="slide">
|
||||
<?php snippet('picture', ['file' => $file, 'srcsetName' => 'home-slideshow', 'sizes' => '100vw', 'lazy' => false]) ?>
|
||||
<?php snippet('picture', ['file' => $slide['file'], 'srcsetName' => 'home-slideshow', 'sizes' => '100vw', 'lazy' => false]) ?>
|
||||
</div>
|
||||
<?php $i++ ?>
|
||||
|
||||
<?php endif ?>
|
||||
<?php endwhile ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<button class="prev"></button>
|
||||
<button class="next"></button>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue