From bdb8613be4542647533ff1c6bb78dcf9b7318be8 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Thu, 20 Jun 2024 09:50:39 +0200 Subject: [PATCH] nav - don't show empty categories --- assets/css/src/generic.css | 6 +- assets/css/style.css | 20 +-- site/collections/categories.php | 30 +++- site/snippets/desktop-nav.php | 55 ++++++ site/snippets/header.php | 2 +- site/snippets/nav.php | 17 ++ site/snippets/panel--categories.php | 90 ++++++++++ site/snippets/panel--years.php | 97 +++++++++++ site/snippets/panels.php | 254 ---------------------------- 9 files changed, 295 insertions(+), 276 deletions(-) create mode 100644 site/snippets/desktop-nav.php create mode 100644 site/snippets/nav.php create mode 100644 site/snippets/panel--categories.php create mode 100644 site/snippets/panel--years.php delete mode 100644 site/snippets/panels.php diff --git a/assets/css/src/generic.css b/assets/css/src/generic.css index e7452aa..255179c 100644 --- a/assets/css/src/generic.css +++ b/assets/css/src/generic.css @@ -6,17 +6,17 @@ body { background-size: var(--unit--horizontal) var(--unit--vertical); background-image: linear-gradient( to right, - var(--color-secondary--x-light) 1px, + var(--color-tertiary--x-light) 1px, transparent 1px ), linear-gradient( to bottom, - var(--color-secondary--light) 1px, + var(--color-tertiary--light) 1px, transparent 1px ), linear-gradient( to bottom, - var(--color-secondary--x-light) 1px, + var(--color-tertiary--x-light) 1px, transparent 1px ); background-position: 0 0, 0 0, 0 calc(var(--unit--vertical) / 2); diff --git a/assets/css/style.css b/assets/css/style.css index ec56b9c..ec23316 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -14,9 +14,16 @@ --color-background: #000; --color-primary: #ffffff; --color-primary--transparent: rgba(255, 255, 255, 0.86); - --color-secondary: rgb(120, 171, 150, 0.86); - --color-secondary--light: rgb(119, 177, 157, 0.2); - --color-secondary--x-light: rgb(119, 177, 157, 0.1); + + --color-secondary-rgb: 120, 171, 150; + --color-secondary: rgba(var(--color-secondary-rgb), 0.86); + --color-secondary--light: rgba(var(--color-secondary-rgb), 0.2); + --color-secondary--x-light: rgb(var(--color-secondary-rgb), 0.1); + + --color-tertiary-rgb: 253, 68, 26; + --color-tertiary: rgba(var(--color-tertiary-rgb), 0.86); + --color-tertiary--light: rgba(var(--color-tertiary-rgb), 0.2); + --color-tertiary--x-light: rgb(var(--color-tertiary-rgb), 0.1); --unit--horizontal: 5vw; --unit--vertical: 1.7rem; @@ -41,13 +48,6 @@ @media screen and (min-width: 640px) { :root { - --color-background: #000; - --color-primary: #ffffff; - --color-primary--transparent: rgba(255, 255, 255, 0.86); - --color-secondary: rgb(120, 171, 150, 0.86); - --color-secondary--light: rgb(119, 177, 157, 0.25); - --color-secondary--x-light: rgb(119, 177, 157, 0.15); - --unit--horizontal: 2.5vw; --unit--vertical: 1.7rem; diff --git a/site/collections/categories.php b/site/collections/categories.php index ad4645a..4d425ed 100644 --- a/site/collections/categories.php +++ b/site/collections/categories.php @@ -1,27 +1,41 @@ find('texts'); - $years = $textsPage->children(); - $texts = $years->children()->index(); - +function createCategories($textsPage) { $categories = array(); - foreach ($textsPage->categories()->split() as $category) { $categories[$category] = array( 'title' => $category, 'texts' => array() ); } + return $categories; +} +function fillCategoriesWithTexts($emptyCategories, $texts) { + $filledCategories = $emptyCategories; foreach ($texts as $text) { try { - $categories[$text->category()->value()]['texts'][] = $text; + $textCategory = $text->category()->value(); + $filledCategories[$textCategory]['texts'][] = $text; } catch (\Throwable $th) { throw new Exception(json_encode($th->getFile() . ' : ' . $th->getMessage())); } } - return $categories; + // exclude empty categories + return array_filter($filledCategories, function($category) { + return count($category['texts']) > 0; + }); +} +return function ($site) { + $textsPage = $site->find('texts'); + $years = $textsPage->children(); + $texts = $years->children()->index(); + + $emptyCategories = createCategories($textsPage); + + $filledCategories = fillCategoriesWithTexts($emptyCategories, $texts); + + return $filledCategories; }; diff --git a/site/snippets/desktop-nav.php b/site/snippets/desktop-nav.php new file mode 100644 index 0000000..72b0e7e --- /dev/null +++ b/site/snippets/desktop-nav.php @@ -0,0 +1,55 @@ + + + + + \ No newline at end of file diff --git a/site/snippets/header.php b/site/snippets/header.php index 9b8fadf..525e46a 100644 --- a/site/snippets/header.php +++ b/site/snippets/header.php @@ -25,4 +25,4 @@ $entryTopPos = $entryTopPos ?? 20; - \ No newline at end of file + \ No newline at end of file diff --git a/site/snippets/nav.php b/site/snippets/nav.php new file mode 100644 index 0000000..dbc2303 --- /dev/null +++ b/site/snippets/nav.php @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/site/snippets/panel--categories.php b/site/snippets/panel--categories.php new file mode 100644 index 0000000..f19b425 --- /dev/null +++ b/site/snippets/panel--categories.php @@ -0,0 +1,90 @@ +