33 lines
808 B
PHP
33 lines
808 B
PHP
<?php
|
|
|
|
use Kirby\Uuid\Uuid;
|
|
|
|
return [
|
|
'pattern' => 'categories/(:any)',
|
|
'action' => function ($category) {
|
|
|
|
$allTexts = page('textes')->grandChildren();
|
|
$textsInCategory = $allTexts->filter(
|
|
fn($text) => Str::slug($text->category()) === $category
|
|
);
|
|
|
|
$children = new Pages();
|
|
|
|
foreach ($textsInCategory as $text) {
|
|
$children->add($text);
|
|
}
|
|
|
|
$title = $textsInCategory->first()->category();
|
|
|
|
return Page::factory([
|
|
'slug' => Str::slug($category) . '-' . Uuid::generate(),
|
|
'template' => 'category',
|
|
'model' => 'category',
|
|
'content' => [
|
|
'title' => $title,
|
|
'uuid' => Uuid::generate(),
|
|
],
|
|
'children' => $children->toArray(),
|
|
]);
|
|
},
|
|
];
|