redesign nav and logo
This commit is contained in:
parent
48bfd23600
commit
cf867bbc14
14 changed files with 315 additions and 297 deletions
|
|
@ -1,41 +1,44 @@
|
|||
<?php
|
||||
|
||||
function createCategories($textsPage) {
|
||||
$categories = array();
|
||||
foreach ($textsPage->categories()->split() as $category) {
|
||||
$categories[$category] = array(
|
||||
'title' => $category,
|
||||
'texts' => new Pages()
|
||||
);
|
||||
}
|
||||
function createEmptyCategories() {
|
||||
$categories = new Pages();
|
||||
foreach (page('textes')->categories()->split() as $categoryName) {
|
||||
$category = new Page([
|
||||
'slug' => Str::slug($categoryName),
|
||||
'template' => 'category',
|
||||
'status' => 'listed',
|
||||
'content' => [
|
||||
'title' => $categoryName,
|
||||
],
|
||||
'children' => []
|
||||
]);
|
||||
|
||||
$categories->add($category);
|
||||
}
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
function fillCategoriesWithTexts($emptyCategories, $texts) {
|
||||
$filledCategories = $emptyCategories;
|
||||
foreach ($texts as $text) {
|
||||
|
||||
function createCategories() {
|
||||
$emptyCategories = createEmptyCategories();
|
||||
foreach (page('textes')->grandChildren() as $text) {
|
||||
try {
|
||||
$textCategory = $text->category()->value();
|
||||
$filledCategories[$textCategory]['texts']->add($text);
|
||||
$textCategoryName = $text->category()->value();
|
||||
$emptyCategories
|
||||
->findBy('slug', Str::slug($textCategoryName))
|
||||
->children()
|
||||
->add($text);
|
||||
} catch (\Throwable $th) {
|
||||
throw new Exception(json_encode($th->getFile() . ' : ' . $th->getMessage()));
|
||||
throw new Exception($th->getFile() . ' : ' . $th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// exclude empty categories
|
||||
return array_filter($filledCategories, function($category) {
|
||||
return count($category['texts']) > 0;
|
||||
return $emptyCategories->filter(function ($category) {
|
||||
return $category->children()->count() > 0;
|
||||
});
|
||||
}
|
||||
|
||||
return function ($site) {
|
||||
$textsPage = $site->find('textes');
|
||||
$years = $textsPage->children();
|
||||
$texts = $years->children()->index();
|
||||
|
||||
$emptyCategories = createCategories($textsPage);
|
||||
|
||||
$filledCategories = fillCategoriesWithTexts($emptyCategories, $texts);
|
||||
|
||||
return $filledCategories;
|
||||
$categories = createCategories();
|
||||
return $categories;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue