diff --git a/site/plugins/toc/index.php b/site/plugins/toc/index.php index e5f16fe..7d022d1 100644 --- a/site/plugins/toc/index.php +++ b/site/plugins/toc/index.php @@ -14,7 +14,7 @@ function getContent($page) { } function getTocContent($page) { - if (!$page->parent()?->parent()?->is('textes')) return null; + if (!$page->parents()->findBy('uri', 'textes')) return null; $content = (string) getContent($page); @@ -34,13 +34,13 @@ Kirby::plugin('actuel-inactuel/toc', [ preg_match_all(HEADING_PATTERN, $content, $matches, PREG_SET_ORDER); $items = []; - foreach ($matches as $m) { - $entry = ['title' => $m[3], 'slug' => Str::slug($m[3])]; + foreach ($matches as $match) { + $entry = ['title' => $match[3], 'slug' => Str::slug($match[3])]; - if ($m[1] === 'h3') { + if ($match[1] === 'h3') { $entry['children'] = []; $items[] = $entry; - } elseif ($m[1] === 'h4' && count($items) > 0) { + } elseif ($match[1] === 'h4' && count($items) > 0) { $items[count($items) - 1]['children'][] = $entry; } } @@ -50,6 +50,7 @@ Kirby::plugin('actuel-inactuel/toc', [ 'bodyWithAnchors' => function(): string { $content = getTocContent($this); + if (!$content) return ''; return preg_replace_callback(