diff --git a/site/plugins/toc/index.php b/site/plugins/toc/index.php index 5a6e97d..c3edad0 100644 --- a/site/plugins/toc/index.php +++ b/site/plugins/toc/index.php @@ -1,28 +1,38 @@ (.*?)<\/h3>/'; + +function getContent($page) { + if ($page->intendedTemplate() == 'grid') return $page->body()->toBlocks(); + + if ($page->intendedTemplate() == 'linear') { + if ($page->isBlockMode()->isTrue()) return $page->bodyBlocks()->toBlocks(); + if ($page->isBlockMode()->isFalse()) return $page->body(); + } + + return null; +} + +function getTocContent($page) { + if (!$page->parent()?->parent()?->is('textes')) return null; + + $content = (string) getContent($page); + + return $content ?: null; +} + Kirby::plugin('actuel-inactuel/toc', [ 'pageMethods' => [ - /** - * Vérifie si la page doit afficher une TOC - */ 'hasToc' => function(): bool { - if (!$this->parent()?->parent()?->is('textes')) { - return false; - } - if (!$this->bodyBlocks()?->isNotEmpty()) { - return false; - } - return (bool) preg_match('/