diff --git a/app/Repos/EntityRepo.php b/app/Repos/EntityRepo.php index 95666a66a..0515a4cd4 100644 --- a/app/Repos/EntityRepo.php +++ b/app/Repos/EntityRepo.php @@ -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; } diff --git a/resources/views/pages/sidebar-tree-list.blade.php b/resources/views/pages/sidebar-tree-list.blade.php index 87eebed49..0fb97369e 100644 --- a/resources/views/pages/sidebar-tree-list.blade.php +++ b/resources/views/pages/sidebar-tree-list.blade.php @@ -30,7 +30,7 @@
{{ trans('entities.pages_navigation') }}