Use a more reliable way to detect the current page, fixes #420
Dieser Commit ist enthalten in:
Ursprung
cf05db04b6
Commit
e831e75958
@ -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) {
|
||||
|
@ -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()) {
|
||||
|
@ -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) {
|
||||
|
@ -189,4 +189,8 @@ abstract class Entry
|
||||
'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 */
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren