Compare commits
No commits in common. "4c26c1444fad7372f362a60c47ca71f3634fed48" and "42704b9cb0d27e5b9cc9ac3f8244e05181b6f70e" have entirely different histories.
4c26c1444f
...
42704b9cb0
|
|
@ -132,48 +132,27 @@ function count_user_articles($userID, $postType)
|
|||
function build_sommaire_from_content($postID)
|
||||
{
|
||||
$blocks = parse_blocks(get_the_content($postID));
|
||||
|
||||
// Collecter les h2 au niveau racine ET dans les innerBlocks immédiats (profondeur 1)
|
||||
$titleBlocks = [];
|
||||
|
||||
$checkIsH2 = function ($block) {
|
||||
if (!is_array($block) || empty($block['blockName'])) return false;
|
||||
if ($block['blockName'] !== 'core/heading') return false;
|
||||
|
||||
// Exclure explicitement les titres marqués avec la classe not-in-index
|
||||
if (!empty($block['attrs']['className']) && strpos($block['attrs']['className'], 'not-in-index') !== false) {
|
||||
return false;
|
||||
}
|
||||
if (!empty($block['innerHTML']) && preg_match('/class="[^"]*not-in-index[^"]*"/i', $block['innerHTML'])) {
|
||||
$titleBlocks = array_filter(
|
||||
$blocks,
|
||||
function ($block) {
|
||||
// Vérifier si c'est un bloc heading
|
||||
if ($block['blockName'] !== 'core/heading') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Utiliser le niveau depuis les attributs si présent
|
||||
if (!empty($block['attrs']['level'])) {
|
||||
return intval($block['attrs']['level']) === 2;
|
||||
}
|
||||
|
||||
// Sinon, détecter <h2> dans le HTML du bloc
|
||||
if (!empty($block['innerHTML']) && preg_match('/<h2[^>]*>/i', $block['innerHTML'])) {
|
||||
// Extraire le niveau depuis le HTML si les attributs sont vides
|
||||
if (empty($block['attrs']['level'])) {
|
||||
// Chercher seulement h2 dans le HTML
|
||||
if (preg_match('/<h2[^>]*>/i', $block['innerHTML'], $matches)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
foreach ($blocks as $block) {
|
||||
if ($checkIsH2($block)) {
|
||||
$titleBlocks[] = $block;
|
||||
}
|
||||
// Parcours des enfants immédiats uniquement
|
||||
if (!empty($block['innerBlocks']) && is_array($block['innerBlocks'])) {
|
||||
foreach ($block['innerBlocks'] as $child) {
|
||||
if ($checkIsH2($child)) {
|
||||
$titleBlocks[] = $child;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Utiliser le niveau des attributs s'il existe
|
||||
return $block['attrs']['level'] === 2;
|
||||
}
|
||||
);
|
||||
|
||||
$outputIndex = [];
|
||||
|
||||
|
|
@ -188,7 +167,7 @@ function build_sommaire_from_content($postID)
|
|||
|
||||
if ($level !== 2) continue;
|
||||
|
||||
$anchor = $block['attrs']['idName'] ?? ($block['attrs']['anchor'] ?? sanitize_title($title));
|
||||
$anchor = $block['attrs']['idName'] ?? sanitize_title($title);
|
||||
|
||||
// Ajouter un préfixe si l'ancre commence par un chiffre
|
||||
if (!empty($anchor) && preg_match('/^[0-9]/', $anchor)) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ $issue_related_articles = get_field('articles', $revueID);
|
|||
<section class="table-matieres">
|
||||
<h3 class="content-tab__title">Table des matières</h3>
|
||||
<ul class="post-grid__list article-grid__list">
|
||||
<?php if ($issue_related_articles && is_array($issue_related_articles)) : ?>
|
||||
<?php foreach ($issue_related_articles as $article) : ?>
|
||||
<?php get_template_part('template-parts/articles/card-article', null, array(
|
||||
|
||||
|
|
@ -18,6 +17,5 @@ $issue_related_articles = get_field('articles', $revueID);
|
|||
'showAuthors' => true,
|
||||
)); ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</section>
|
||||
Loading…
Reference in New Issue
Block a user