diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index 4cc70650..960af804 100755 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -189,6 +189,8 @@ function () use ($node, $output_dir, $key, $params, $index_pages) { return; } + $this->daux->tree->setActiveNode($node); + $generated = $this->generateOne($node, $params); file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $generated->getContent()); if ($index_pages) { diff --git a/libs/Format/HTML/Template.php b/libs/Format/HTML/Template.php index dd245c8f..30aa0f41 100644 --- a/libs/Format/HTML/Template.php +++ b/libs/Format/HTML/Template.php @@ -119,18 +119,16 @@ private function buildNavigation(Directory $tree, $path, $current_url, $base_pag $nav[] = [ 'title' => $node->getTitle(), 'href' => $base_page . $link, - 'class' => $current_url === $link ? 'Nav__item--active' : '', + 'class' => $node->isHotPath() ? 'Nav__item--active' : '', ]; } elseif ($node instanceof Directory) { if (!$node->hasContent()) { continue; } - $link = ($path === '') ? $url : $path . '/' . $url; - $folder = [ 'title' => $node->getTitle(), - 'class' => strpos($current_url, $link) === 0 ? 'Nav__item--open' : '', + 'class' => $node->isHotPath() ? 'Nav__item--open' : '', ]; if ($index = $node->getIndexPage()) { diff --git a/libs/Server/Server.php b/libs/Server/Server.php index 0d6d653a..897837a2 100755 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -157,6 +157,8 @@ private function getPage($request) throw new NotFoundException('The Page you requested is yet to be made. Try again later.'); } + $this->daux->tree->setActiveNode($file); + $generator = $this->daux->getGenerator(); if (!$generator instanceof LiveGenerator) { diff --git a/libs/Tree/Entry.php b/libs/Tree/Entry.php index 5722dc5d..7543041b 100644 --- a/libs/Tree/Entry.php +++ b/libs/Tree/Entry.php @@ -189,4 +189,8 @@ public function dump() 'path' => $this->path, ]; } + + public function isHotPath(Entry $node = null) { + return $this->parent->isHotPath($node ?: $this); + } } diff --git a/libs/Tree/Root.php b/libs/Tree/Root.php index d579584c..b286ade1 100644 --- a/libs/Tree/Root.php +++ b/libs/Tree/Root.php @@ -7,6 +7,9 @@ class Root extends Directory /** @var Config */ protected $config; + /** @var Entry */ + protected $activeNode; + /** * The root doesn't have a parent */ @@ -33,4 +36,30 @@ public function setConfig($config) { $this->config = $config; } + + public function isHotPath(Entry $node = null) { + if ($node == null) { + return true; + } + + if ($this->activeNode == null) { + return false; + } + + if ($node == $this->activeNode) { + return true; + } + + foreach ($this->activeNode->getParents() as $parent) { + if ($node == $parent) { + return true; + } + } + + return false; + } + + public function setActiveNode(Entry $node) { + $this->activeNode = $node; + } }