This commit is contained in:
isUnknown 2025-02-03 16:32:36 +01:00
parent 1e91353c86
commit fc267d80d1
5 changed files with 110 additions and 51 deletions

View file

@ -9,6 +9,14 @@ article #main-content {
font-style: italic; font-style: italic;
} }
#main-content .texts {
margin-top: calc(2 * var(--unit--vertical));
}
#main-content .see-more {
margin-top: calc(var(--unit--vertical) * 0.5);
}
#chapo em { #chapo em {
font-style: normal; font-style: normal;
} }

View file

@ -1,3 +1,4 @@
<?php <?php
use Kirby\Uuid\Uuid; use Kirby\Uuid\Uuid;
@ -5,18 +6,14 @@ use Kirby\Uuid\Uuid;
return [ return [
'pattern' => 'categories/(:any)', 'pattern' => 'categories/(:any)',
'action' => function ($category) { 'action' => function ($category) {
$kirby = kirby(); return Page::factory([
'slug' => Str::slug($category) . '-' . Uuid::generate(),
return Page::factory( 'template' => 'category',
[ 'model' => 'category',
'slug' => '', 'content' => [
'template' => 'category',
'model' => 'categories',
'content' => [
'title' => $category, 'title' => $category,
'uuid' => Uuid::generate(), 'uuid' => Uuid::generate(),
] ],
] ]);
);
} }
]; ];

23
site/models/category.php Normal file
View file

@ -0,0 +1,23 @@
<?php
use Kirby\Cms\Pages;
use Kirby\Cms\Page;
use Kirby\Uuid\Uuid;
class CategoryPage extends Page
{
public function children(): Pages
{
$category = $this->title()->value();
$allTexts = page("textes")->grandChildren();
$textsInCategory = $allTexts->filterBy('category', $category);
$children = new Pages();
foreach ($textsInCategory as $text) {
$children->add($text);
}
return $children;
}
}

View file

@ -1,36 +1,58 @@
<?php snippet('header'); ?> <?php snippet('header') ?>
<main id="<?= $page->template() ?>"> <main id="<?= $page->template() ?>">
<article> <article>
<?php snippet('cover', slots: true) ?> <?php snippet('cover', array('isOpen' => true), slots: true) ?>
<?php slot('title') ?> <?php slot('title') ?>
<?php endslot() ?> <h1 class="main-title"><?= $page->title() ?></h1>
<?php slot('text') ?> <?php endslot() ?>
<h2 class="main-title <?= setTitleFontSizeClass($page->title()) ?>"><?= $page->title() ?></h2> <?php endsnippet() ?>
<div id="main-content"
x-data="{
edito: false
}"
>
<?php if ($page->edito()->isNotEmpty()): ?>
<div
id="edito"
:class="edito ? '' : 'short'"
>
<?= $page->edito() ?>
</div>
<button
:class="edito ? 'open' : 'close'"
class="see-more toggle-btn toggle-btn--left"
@click="edito = !edito"
>Lire</button>
<?php endif ?>
<ul class="texts"> <ul class="texts">
<?php foreach($kirby->collection('categories') as $category): ?> <?php foreach($page->children() as $article): ?>
<?php if ($category->title() == $page->title()): ?> <li
<?php foreach($category['texts'] as $article): ?> class="text"
<li >
class="text" <a href="<?= $article->url() ?>" class="text__title no-underline">
> <h4><?= $article->title() ?></h4>
<a href="<?= $article->url() ?>" class="text__title no-underline"> </a>
<h4><?= $article->title() ?></h4> <div class="text__infos">
</a> <p>
<div class="text__infos"> <span class="light">par</span>
<p> <?php
<span class="light">par</span> try {
<a class="author" href="/auteurs/<?= Str::slug($article->author()->toPage()->title()) ?>"><?= $article->author()->toPage()->title() ?></a><br> echo $article->author()->toPage()->title();
<span class="light">publié le </span><?= $article->published()->toDate('d/m/Y') ?><br> } catch (\Throwable $th) {
<span class="light">dans</span> <a href="<?= $article->parent()->url() ?>"><?= $article->parent()->title() ?></a> / <a href="/categories/<?= $article->category() ?>"><?= $article->category() ?></a> throw new Exception(json_encode($article->author()), 1);
</p>
</div> }
</li> ?>
<?php endforeach ?> <a class="author" href="/auteurs/<?= Str::slug($article->author()->toPage()->title()) ?>"><?= $article->author()->toPage()->title() ?></a><br>
<?php endif ?> <span class="light">publié le </span><?= $article->published()->toDate('d/m/Y') ?><br>
</ul> <span class="light">dans</span> <a href="<?= $article->parent()->url() ?>"><?= $article->parent()->title() ?></a> / <a href="/categories/<?= $article->category() ?>"><?= $article->category() ?></a>
</p>
</div>
</li>
<?php endforeach ?> <?php endforeach ?>
<?php endslot() ?> </div>
<?php endsnippet() ?> </article>
</article> </main>
</main>
<?php snippet('footer') ?>

View file

@ -4,20 +4,29 @@
<?php snippet('cover', array('isOpen' => true), slots: true) ?> <?php snippet('cover', array('isOpen' => true), slots: true) ?>
<?php slot('title') ?> <?php slot('title') ?>
<h1 class="main-title"><?= $page->title() ?></h1> <h1 class="main-title"><?= $page->title() ?></h1>
<?php if ($page->subtitle()->isNotEmpty()): ?>
<h2 class="main-subtitle fs-l"><?= $page->subtitle()->inline() ?></h2>
<?php endif ?>
<p> <p>
<span class="light">ouverte depuis le </span><?= $page->openDate()->toDate('d/m/Y') ?> <span class="light">ouverte depuis le </span><?= $page->openDate()->toDate('d/m/Y') ?>
</p> </p>
<?php endslot() ?> <?php endslot() ?>
<?php endsnippet() ?> <?php endsnippet() ?>
<div id="main-content"> <div id="main-content"
<?php if ($page->chapo()->isNotEmpty()): ?> x-data="{
<div id="chapo"> edito: false
<?= $page->chapo() ?> }"
>
<?php if ($page->edito()->isNotEmpty()): ?>
<div
id="edito"
:class="edito ? '' : 'short'"
>
<?= $page->edito() ?>
</div> </div>
<button
:class="edito ? 'open' : 'close'"
class="see-more toggle-btn toggle-btn--left"
@click="edito = !edito"
>Lire</button>
<?php endif ?> <?php endif ?>
<ul class="texts"> <ul class="texts">
<?php foreach($page->children() as $article): ?> <?php foreach($page->children() as $article): ?>