mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 20:22:18 +00:00
Normalised page nav header inset when only small headers are used
This commit is contained in:
parent
3595ac2551
commit
7c8c4c2a05
@ -836,7 +836,7 @@ class EntityRepo
|
||||
/**
|
||||
* Parse the headers on the page to get a navigation menu
|
||||
* @param Page $page
|
||||
* @return array
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPageNav(Page $page)
|
||||
{
|
||||
@ -849,15 +849,24 @@ class EntityRepo
|
||||
|
||||
if (is_null($headers)) return null;
|
||||
|
||||
$tree = [];
|
||||
$tree = collect([]);
|
||||
foreach ($headers as $header) {
|
||||
$text = $header->nodeValue;
|
||||
$tree[] = [
|
||||
$tree->push([
|
||||
'nodeName' => strtolower($header->nodeName),
|
||||
'level' => intval(str_replace('h', '', $header->nodeName)),
|
||||
'link' => '#' . $header->getAttribute('id'),
|
||||
'text' => strlen($text) > 30 ? substr($text, 0, 27) . '...' : $text
|
||||
];
|
||||
]);
|
||||
}
|
||||
|
||||
// Normalise headers if only smaller headers have been used
|
||||
if (count($tree) > 0) {
|
||||
$minLevel = $tree->pluck('level')->min();
|
||||
$tree = $tree->map(function($header) use ($minLevel) {
|
||||
$header['level'] -= ($minLevel - 2);
|
||||
return $header;
|
||||
});
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
<h6 class="text-muted">{{ trans('entities.pages_navigation') }}</h6>
|
||||
<div class="sidebar-page-nav menu">
|
||||
@foreach($pageNav as $navItem)
|
||||
<li class="page-nav-item {{ $navItem['nodeName'] }}">
|
||||
<li class="page-nav-item h{{ $navItem['level'] }}">
|
||||
<a href="{{ $navItem['link'] }}">{{ $navItem['text'] }}</a>
|
||||
</li>
|
||||
@endforeach
|
||||
|
Loading…
Reference in New Issue
Block a user