actuel-inactuel/site/config/routes/virtual-category.php

38 lines
890 B
PHP
Raw Permalink Normal View History

2024-04-06 10:08:45 +02:00
<?php
use Kirby\Uuid\Uuid;
return [
'pattern' => 'categories/(:any)',
'action' => function ($category) {
2025-02-21 13:08:53 +01:00
$allTexts = page('textes')->grandChildren();
$textsInCategory = $allTexts->filter(
fn($text) => Str::slug($text->category()) === $category
);
2025-02-21 13:24:06 +01:00
$texts = [];
2025-02-21 13:08:53 +01:00
foreach ($textsInCategory as $text) {
2025-02-21 13:24:06 +01:00
$texts[] = (string) $text->uri();
2025-02-21 13:08:53 +01:00
}
2025-02-21 13:24:06 +01:00
try {
$title = $textsInCategory->first()->category();
} catch (\Throwable $th) {
go('/erreur');
}
2025-02-21 13:08:53 +01:00
2025-02-03 16:32:36 +01:00
return Page::factory([
'slug' => Str::slug($category) . '-' . Uuid::generate(),
'template' => 'category',
'model' => 'category',
'content' => [
2025-02-21 13:08:53 +01:00
'title' => $title,
2025-02-21 13:24:06 +01:00
'texts' => Yaml::encode($texts),
2024-04-06 10:08:45 +02:00
'uuid' => Uuid::generate(),
2025-02-03 16:32:36 +01:00
],
]);
2025-02-21 13:08:53 +01:00
},
2024-04-06 10:08:45 +02:00
];