mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-09-13 13:04:52 +00:00
Updated page nav to hide when empty
This commit is contained in:
parent
581c382f65
commit
969ad8911c
@ -836,18 +836,18 @@ class EntityRepo
|
|||||||
/**
|
/**
|
||||||
* Parse the headers on the page to get a navigation menu
|
* Parse the headers on the page to get a navigation menu
|
||||||
* @param Page $page
|
* @param Page $page
|
||||||
* @return Collection
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getPageNav(Page $page)
|
public function getPageNav(Page $page)
|
||||||
{
|
{
|
||||||
if ($page->html == '') return null;
|
if ($page->html == '') return [];
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
$doc = new DOMDocument();
|
$doc = new DOMDocument();
|
||||||
$doc->loadHTML(mb_convert_encoding($page->html, 'HTML-ENTITIES', 'UTF-8'));
|
$doc->loadHTML(mb_convert_encoding($page->html, 'HTML-ENTITIES', 'UTF-8'));
|
||||||
$xPath = new DOMXPath($doc);
|
$xPath = new DOMXPath($doc);
|
||||||
$headers = $xPath->query("//h1|//h2|//h3|//h4|//h5|//h6");
|
$headers = $xPath->query("//h1|//h2|//h3|//h4|//h5|//h6");
|
||||||
|
|
||||||
if (is_null($headers)) return null;
|
if (is_null($headers)) return [];
|
||||||
|
|
||||||
$tree = collect([]);
|
$tree = collect([]);
|
||||||
foreach ($headers as $header) {
|
foreach ($headers as $header) {
|
||||||
@ -868,7 +868,7 @@ class EntityRepo
|
|||||||
return $header;
|
return $header;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return $tree;
|
return $tree->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if (isset($pageNav) && $pageNav)
|
@if (isset($pageNav) && count($pageNav))
|
||||||
<h6 class="text-muted">{{ trans('entities.pages_navigation') }}</h6>
|
<h6 class="text-muted">{{ trans('entities.pages_navigation') }}</h6>
|
||||||
<div class="sidebar-page-nav menu">
|
<div class="sidebar-page-nav menu">
|
||||||
@foreach($pageNav as $navItem)
|
@foreach($pageNav as $navItem)
|
||||||
|
Loading…
Reference in New Issue
Block a user