task-17075__opdate-blog #1

Merged
web_103.2 merged 37 commits from task-17075__opdate-blog into master 2026-10-26 13:36:52 +03:00
Showing only changes of commit 2e54c26224 - Show all commits
+23 -1
View File
@@ -16,6 +16,26 @@
$terms = get_the_terms(get_the_ID(), 'article_category');
$article_blocks = get_field('new_blocks') ?: [];
$article_content = get_field('article_content') ?: '';
$reading_parts = [$article_content];
foreach ($article_blocks as $block) {
$layout = $block['acf_fc_layout'] ?? '';
if ($layout === 'text') {
$reading_parts[] = $block['content'] ?? '';
} elseif (in_array($layout, ['attention_block', 'attention_blocks', 'quote'], true)) {
$reading_parts[] = $block['text'] ?? '';
} elseif ($layout === 'block_main') {
foreach (($block['cards'] ?? []) as $card) {
$reading_parts[] = $card['text_card'] ?? '';
}
}
}
// Разделяем HTML-элементы пробелами, чтобы соседние абзацы не склеивались.
$reading_text = strip_shortcodes(implode(' ', $reading_parts));
$reading_text = preg_replace('@<(script|style)\b[^>]*>.*?</\1>@si', ' ', $reading_text);
$reading_text = preg_replace('/<[^>]*>/', ' ', $reading_text);
$reading_text = html_entity_decode(wp_strip_all_tags($reading_text), ENT_QUOTES | ENT_HTML5, 'UTF-8');
$word_count = preg_match_all("/[\p{L}\p{N}]+(?:[’'\x{002D}][\p{L}\p{N}]+)*/u", $reading_text);
$reading_minutes = $word_count ? max(1, (int) ceil($word_count / 200)) : 0;
$generated = generate_toc($article_content, 'article-content');
$content = $generated['content'];
$toc_items = $generated['toc_items'];
@@ -70,13 +90,15 @@
<time datetime="<?php echo esc_attr(get_the_date('c')); ?>"><?php echo esc_html(get_the_date('d.m.Y')); ?></time>
</div>
<?php if ($reading_minutes) : ?>
<div class="h-article-hero__meta-item">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<circle cx="12" cy="13" r="9"></circle>
<path d="M12 8v5l3 2M9 2h6"></path>
</svg>
<span>Время чтения: <strong>—</strong></span>
<span>Время чтения: <strong>≈ <?php echo esc_html($reading_minutes); ?> мин</strong></span>
</div>
<?php endif; ?>
<div class="h-article-hero__meta-item">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">