2024-04-09 10:44:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
2025-02-04 17:35:09 +01:00
|
|
|
function createEmptyCategories()
|
|
|
|
|
{
|
|
|
|
|
$categories = new Pages();
|
2024-11-26 09:53:05 +01:00
|
|
|
foreach (page('textes')->categories()->split() as $categoryName) {
|
|
|
|
|
$category = new Page([
|
2025-02-04 17:35:09 +01:00
|
|
|
'slug' => Str::slug($categoryName),
|
2024-11-26 09:53:05 +01:00
|
|
|
'template' => 'category',
|
2025-02-04 17:35:09 +01:00
|
|
|
'status' => 'listed',
|
|
|
|
|
'content' => [
|
2024-11-26 09:53:05 +01:00
|
|
|
'title' => $categoryName,
|
|
|
|
|
],
|
2025-02-04 17:35:09 +01:00
|
|
|
'children' => [],
|
2024-11-26 09:53:05 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$categories->add($category);
|
2025-02-04 17:35:09 +01:00
|
|
|
}
|
2024-11-26 09:53:05 +01:00
|
|
|
|
2024-06-20 09:50:39 +02:00
|
|
|
return $categories;
|
|
|
|
|
}
|
2024-04-09 10:44:12 +02:00
|
|
|
|
2024-11-26 09:53:05 +01:00
|
|
|
|
2025-02-04 17:35:09 +01:00
|
|
|
function createCategories()
|
|
|
|
|
{
|
2024-11-26 09:53:05 +01:00
|
|
|
$emptyCategories = createEmptyCategories();
|
|
|
|
|
foreach (page('textes')->grandChildren() as $text) {
|
2024-04-09 10:44:12 +02:00
|
|
|
try {
|
2024-11-26 09:53:05 +01:00
|
|
|
$textCategoryName = $text->category()->value();
|
|
|
|
|
$emptyCategories
|
|
|
|
|
->findBy('slug', Str::slug($textCategoryName))
|
|
|
|
|
->children()
|
|
|
|
|
->add($text);
|
2024-04-09 10:44:12 +02:00
|
|
|
} catch (\Throwable $th) {
|
2024-11-26 09:53:05 +01:00
|
|
|
throw new Exception($th->getFile() . ' : ' . $th->getMessage());
|
2024-04-09 10:44:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-11-26 09:53:05 +01:00
|
|
|
return $emptyCategories->filter(function ($category) {
|
|
|
|
|
return $category->children()->count() > 0;
|
2024-06-20 09:50:39 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return function ($site) {
|
2024-11-26 09:53:05 +01:00
|
|
|
$categories = createCategories();
|
|
|
|
|
return $categories;
|
2024-04-09 10:44:12 +02:00
|
|
|
};
|