diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index 4cc7065..960af80 100755 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -189,6 +189,8 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator 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 dd245c8..30aa0f4 100644 --- a/libs/Format/HTML/Template.php +++ b/libs/Format/HTML/Template.php @@ -119,18 +119,16 @@ class Template $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 0d6d653..897837a 100755 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -157,6 +157,8 @@ class Server 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 5722dc5..7543041 100644 --- a/libs/Tree/Entry.php +++ b/libs/Tree/Entry.php @@ -189,4 +189,8 @@ abstract class Entry '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 d579584..b286ade 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 @@ class Root extends Directory { $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; + } }