actuel-inactuel/site/collections/categories.php
2024-04-09 10:44:12 +02:00

27 lines
650 B
PHP

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