@extends('public.layout') @php if (!function_exists('calculateReadingTime')) { function calculateReadingTime($body) { if (!$body) { return 2; } $text = strip_tags($body); $words = str_word_count($text); $minutes = ceil($words / 200); return max(1, $minutes); } } @endphp @php // Garantir que seoData existe e tem valores padrão if (!isset($seoData)) { $seoData = []; } // Adicionar breadcrumbs para SEO $seoData['breadcrumbs'] = [['name' => 'Home', 'url' => url('/')]]; if (isset($article) && $article->section) { $seoData['breadcrumbs'][] = [ 'name' => $article->section->name, 'url' => url("/{$article->section->slug}"), ]; } if (isset($article)) { $seoData['breadcrumbs'][] = [ 'name' => $article->title, 'url' => url()->current(), ]; } // Garantir tipo de conteúdo $seoData['type'] = 'article'; @endphp @section('seo') @php // Passar dados de SEO para o layout // O layout já acessa $seoData diretamente @endphp @endsection @section('content') {{-- Banner antes do conteúdo do artigo --}} @include('components.banners', [ 'regionCode' => 'antes-conteudo', 'sectionId' => $article->section_id ?? null, ])
@include('components.banners', [ 'regionCode' => 'topo', 'sectionId' => $article->section_id ?? null, ])
Home @if ($article->section) {{ $article->section->name }} @endif {{ $article->title }}
@if ($article->section) {{ $article->section->name }} @endif

{{ $article->title }}

@if ($article->headline)

{{ $article->headline }}

@endif
Envie
@php $topImage = $article->topImage ?? $article->featuredImage; @endphp @if ($topImage)
{{ $article->title }} @if ($topImage->caption)
{{ $topImage->caption }}
@endif
@endif
Envie
@php use App\Helpers\BannerHelper; $content = $article->content_html ?? ($article->body ?? ''); // Remover top_image e imagens duplicadas do conteúdo if ($topImage && $topImage->file_url && $content) { $topImageUrl = $topImage->file_url; $topImagePath = parse_url($topImageUrl, PHP_URL_PATH); $topImageBasename = basename($topImagePath); // Normalizar URLs para comparação $normalizedTopImageUrl = rtrim($topImageUrl, '/'); $normalizedTopImagePath = rtrim($topImagePath, '/'); // Remover TODAS as ocorrências da top_image (loop até não haver mais) $figurePatterns = [ // Figura com classe image-block e data-type '/]*class=["\'][^"\']*image-block[^"\']*["\'][^>]*data-type=["\']imageBlock["\'][^>]*>.*?]*src=["\'][^"\']*' . preg_quote($topImageBasename, '/') . '[^"\']*["\'][^>]*>.*?<\/figure>/is', // Qualquer
que contenha a URL completa '/]*>.*?]*src=["\']?' . preg_quote($normalizedTopImageUrl, '/') . '[^>]*>.*?<\/figure>/is', //
com basename (mais flexível) '/]*>.*?]*src=["\'][^"\']*' . preg_quote($topImageBasename, '/') . '[^"\']*["\'][^>]*>.*?<\/figure>/is', //
com path normalizado '/]*>.*?]*src=["\'][^"\']*' . preg_quote($normalizedTopImagePath, '/') . '[^"\']*["\'][^>]*>.*?<\/figure>/is', ]; // Remover todas as ocorrências de
$previousContent = ''; $iterations = 0; while ($content !== $previousContent && $iterations < 10) { $previousContent = $content; foreach ($figurePatterns as $pattern) { $content = preg_replace($pattern, '', $content); } $iterations++; } // Padrões para remover tags soltas $imgPatterns = [ '/]*src=["\']?' . preg_quote($normalizedTopImageUrl, '/') . '[^>]*>/i', '/]*src=["\'][^"\']*' . preg_quote($topImageBasename, '/') . '[^"\']*["\'][^>]*>/i', '/]*src=["\'][^"\']*' . preg_quote($normalizedTopImagePath, '/') . '[^"\']*["\'][^>]*>/i', ]; // Remover todas as ocorrências de $previousContent = ''; $iterations = 0; while ($content !== $previousContent && $iterations < 10) { $previousContent = $content; foreach ($imgPatterns as $pattern) { $content = preg_replace($pattern, '', $content); } $iterations++; } // Remover body_images que são a mesma imagem da top_image if ($article->bodyImages) { foreach ($article->bodyImages as $bodyImage) { $bodyImageUrl = $bodyImage->file_url; $bodyImagePath = parse_url($bodyImageUrl, PHP_URL_PATH); $bodyImageBasename = basename($bodyImagePath); // Comparar usando basename (mais confiável) if ( $bodyImageBasename === $topImageBasename || $bodyImageUrl === $topImageUrl || basename($bodyImagePath) === basename($topImagePath) ) { // Remover esta body_image também $normalizedBodyImageUrl = rtrim($bodyImageUrl, '/'); $bodyImagePatterns = [ '/]*>.*?]*src=["\']?' . preg_quote($normalizedBodyImageUrl, '/') . '[^>]*>.*?<\/figure>/is', '/]*>.*?]*src=["\'][^"\']*' . preg_quote($bodyImageBasename, '/') . '[^"\']*["\'][^>]*>.*?<\/figure>/is', '/]*src=["\']?' . preg_quote($normalizedBodyImageUrl, '/') . '[^>]*>/i', '/]*src=["\'][^"\']*' . preg_quote($bodyImageBasename, '/') . '[^"\']*["\'][^>]*>/i', ]; // Remover todas as ocorrências desta body_image $previousContent = ''; $iterations = 0; while ( $content !== $previousContent && $iterations < 10 ) { $previousContent = $content; foreach ($bodyImagePatterns as $pattern) { $content = preg_replace($pattern, '', $content); } $iterations++; } } } } // Limpar espaços e quebras de linha vazias $content = preg_replace('/\n\s*\n\s*\n+/', "\n\n", $content); $content = preg_replace('/

\s*<\/p>/i', '', $content); $content = preg_replace('/

\s*<\/div>/i', '', $content); $content = preg_replace('/\s+/', ' ', $content); $content = trim($content); } // Inserir banner após o segundo parágrafo if ($content) { $bannerHtml = '
' . BannerHelper::renderBanners( 'meio-conteudo', $article->section_id ?? null, false, ) . '
'; // Encontrar o segundo parágrafo

$paragraphPattern = '/]*>.*?<\/p>/is'; preg_match_all( $paragraphPattern, $content, $matches, PREG_OFFSET_CAPTURE, ); if (isset($matches[0][3])) { // Segundo parágrafo encontrado $thirdParagraph = $matches[0][2]; $position = $thirdParagraph[1] + strlen($thirdParagraph[0]); $content = substr_replace($content, $bannerHtml, $position, 0); } } @endphp {!! $content !!}

@if ($article->tags->count() > 0)
@endif
@include('components.banners', [ 'regionCode' => 'depois-conteudo', 'sectionId' => $article->section_id ?? null, ])
@if ($adjacentPosts['previous']) @php $prevImage = $adjacentPosts['previous']->featuredImage ?? $adjacentPosts['previous']->topImage; $prevImageUrl = $prevImage?->file_url; $prevUrl = url("/{$adjacentPosts['previous']->slug}"); @endphp @endif @if ($adjacentPosts['next']) @php $nextImage = $adjacentPosts['next']->featuredImage ?? $adjacentPosts['next']->topImage; $nextImageUrl = $nextImage?->file_url; $nextUrl = url("/{$adjacentPosts['next']->slug}"); @endphp @endif
{{-- Seção de Comentários --}} @include('components.comments', ['article' => $article])
@include('components.related-articles', ['relatedArticles' => $relatedArticles ?? collect([])])
@endsection