fill categories panel

This commit is contained in:
isUnknown 2024-04-09 10:44:12 +02:00
parent a2722a0264
commit 93a628ec57
5 changed files with 108 additions and 47 deletions

View file

@ -0,0 +1,27 @@
<?php
return function ($site) {
$textsPage = $site->find('texts');
$years = $textsPage->children();
$texts = $years->children()->index();
$categories = array();
foreach ($textsPage->categories()->split() as $category) {
$categories[$category] = array(
'title' => $category,
'texts' => array()
);
}
foreach ($texts as $text) {
try {
$categories[$text->category()->value()]['texts'][] = $text;
} catch (\Throwable $th) {
throw new Exception(json_encode($th->getFile() . ' : ' . $th->getMessage()));
}
}
return $categories;
};

View file

@ -11,32 +11,30 @@
</div>
<nav class="panel panel--left">
<ul
class="years"
>
<ul>
<?php foreach($kirby->collection('years') as $year): ?>
<li
class="year"
class="panel__item "
x-data='{ year: false }'
>
<button
class="year__toggle"
class="panel__toggle-btn"
:class="year ? '' : 'short'"
@click="year = !year"
>
<h3 class="fs-xl color" style="--color:var(--color-secondary)"><?= $year->title() ?></h3>
<div
class="year__toggle-icon"
class="panel__toggle-icon"
x-text="year ? '-' : '+'"
></div>
</button>
<div
class="year__content"
class="panel-item-content"
x-show="year"
x-data="{edito: false}"
>
<div
class="year__edito"
class="panel-item-content__edito"
:class="edito ? '' : 'short'"
>
<?= $year->edito() ?>
@ -45,7 +43,7 @@
:class="edito ? 'open' : 'close'"
class="see-more toggle left" @click="edito = !edito"
>Lire</button>
<ul class="year__texts">
<ul class="panel-item-content__texts">
<?php foreach($year->children() as $article): ?>
<?php snippet(
'text-item',
@ -60,11 +58,47 @@
<button
onclick="togglePanel('left')"
class="panel-close">
</button>
class="panel-close"
>fermer</button>
</nav>
<nav
onclick="togglePanel('right')"
class="panel panel--right"></nav>
<nav class="panel panel--right">
<ul>
<?php foreach($kirby->collection('categories') as $category): ?>
<li
class="panel__item"
x-data='{ category: false }'
>
<button
class="panel__toggle-btn"
:class="category ? '' : 'short'"
@click="category = !category"
>
<h3 class="fs-xl color" style="--color:var(--color-secondary)"><?= $category['title'] ?></h3>
<div
class="panel__toggle-icon"
x-text="category ? '-' : '+'"
></div>
</button>
<div
class="panel-item-content"
x-show="category"
>
<ul class="panel-item-content__texts">
<?php foreach($category['texts'] as $article): ?>
<?php snippet(
'text-item',
array('article' => $article)
) ?>
<?php endforeach ?>
</ul>
</div>
</li>
<?php endforeach ?>
</ul>
<button
onclick="togglePanel('right')"
class="panel-close"
>fermer</button>
</nav>

View file

@ -8,15 +8,7 @@
et des techniques<br>
</h2>
<?php endslot() ?>
<?php slot('tabs') ?>
<?php snippet('tabs', [
'left' => [
'label' => 'édito',
'content' => $site->edito()
]
]) ?>
<?php endslot() ?>
<?php endsnippet() ?>
<?php snippet('nav') ?>
</main>
<?php snippet('footer') ?>