diff --git a/libs/Format/HTML/Template.php b/libs/Format/HTML/Template.php index 484a360..5072560 100644 --- a/libs/Format/HTML/Template.php +++ b/libs/Format/HTML/Template.php @@ -108,6 +108,10 @@ class Template 'class' => ($current_url === $link) ? 'active' : '' ]; } elseif ($node instanceof Directory) { + if (!$node->hasContent()) { + continue; + } + $link = ($path === '') ? $url : $path . '/' . $url; $folder = [ diff --git a/libs/Tree/Directory.php b/libs/Tree/Directory.php index a994b79..548cc5e 100644 --- a/libs/Tree/Directory.php +++ b/libs/Tree/Directory.php @@ -98,6 +98,27 @@ class Directory extends Entry $this->first_page = $first_page; } + /** + * Used when creating the navigation. + * Hides folders without showable content + * + * @return bool + */ + public function hasContent() + { + foreach ($this->getEntries() as $node) { + if ($node instanceof Content) { + return true; + } elseif ($node instanceof Directory) { + if ($node->hasContent()) { + return true; + } + } + } + + return false; + } + private function compareEntries($a, $b) { $name_a = explode('_', $a->name);