fill categories panel
This commit is contained in:
parent
a2722a0264
commit
93a628ec57
5 changed files with 108 additions and 47 deletions
27
site/collections/categories.php
Normal file
27
site/collections/categories.php
Normal 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;
|
||||
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue