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;
};