Use a more reliable way to detect the current page, fixes #420
This commit is contained in:
parent
cf05db04b6
commit
e831e75958
@ -189,6 +189,8 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->daux->tree->setActiveNode($node);
|
||||||
|
|
||||||
$generated = $this->generateOne($node, $params);
|
$generated = $this->generateOne($node, $params);
|
||||||
file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $generated->getContent());
|
file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $generated->getContent());
|
||||||
if ($index_pages) {
|
if ($index_pages) {
|
||||||
|
@ -119,18 +119,16 @@ class Template
|
|||||||
$nav[] = [
|
$nav[] = [
|
||||||
'title' => $node->getTitle(),
|
'title' => $node->getTitle(),
|
||||||
'href' => $base_page . $link,
|
'href' => $base_page . $link,
|
||||||
'class' => $current_url === $link ? 'Nav__item--active' : '',
|
'class' => $node->isHotPath() ? 'Nav__item--active' : '',
|
||||||
];
|
];
|
||||||
} elseif ($node instanceof Directory) {
|
} elseif ($node instanceof Directory) {
|
||||||
if (!$node->hasContent()) {
|
if (!$node->hasContent()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$link = ($path === '') ? $url : $path . '/' . $url;
|
|
||||||
|
|
||||||
$folder = [
|
$folder = [
|
||||||
'title' => $node->getTitle(),
|
'title' => $node->getTitle(),
|
||||||
'class' => strpos($current_url, $link) === 0 ? 'Nav__item--open' : '',
|
'class' => $node->isHotPath() ? 'Nav__item--open' : '',
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($index = $node->getIndexPage()) {
|
if ($index = $node->getIndexPage()) {
|
||||||
|
@ -157,6 +157,8 @@ class Server
|
|||||||
throw new NotFoundException('The Page you requested is yet to be made. Try again later.');
|
throw new NotFoundException('The Page you requested is yet to be made. Try again later.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->daux->tree->setActiveNode($file);
|
||||||
|
|
||||||
$generator = $this->daux->getGenerator();
|
$generator = $this->daux->getGenerator();
|
||||||
|
|
||||||
if (!$generator instanceof LiveGenerator) {
|
if (!$generator instanceof LiveGenerator) {
|
||||||
|
@ -189,4 +189,8 @@ abstract class Entry
|
|||||||
'path' => $this->path,
|
'path' => $this->path,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isHotPath(Entry $node = null) {
|
||||||
|
return $this->parent->isHotPath($node ?: $this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@ class Root extends Directory
|
|||||||
/** @var Config */
|
/** @var Config */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
/** @var Entry */
|
||||||
|
protected $activeNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The root doesn't have a parent
|
* The root doesn't have a parent
|
||||||
*/
|
*/
|
||||||
@ -33,4 +36,30 @@ class Root extends Directory
|
|||||||
{
|
{
|
||||||
$this->config = $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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user