useEffect(() => { const urlParams = new URLSearchParams(window.location.search); const isPaginaNoticia = urlParams.has('id'); if (noticiaSelecionada) { document.title = noticiaSelecionada.titulo; const atualizarMetaTag = (nome, conteudo) => { let tag = document.querySelector(`meta[property="${nome}"]`) || document.querySelector(`meta[name="${nome}"]`); if (!tag) { tag = document.createElement('meta'); tag.setAttribute(nome.startsWith('og:') ? 'property' : 'name', nome); document.head.appendChild(tag); } if (conteudo) tag.setAttribute('content', conteudo); }; atualizarMetaTag('og:title', noticiaSelecionada.titulo); atualizarMetaTag('og:description', noticiaSelecionada.subtitulo || 'Confira esta notícia no Ativa News'); atualizarMetaTag('og:image', noticiaSelecionada.imagem); atualizarMetaTag('og:url', window.location.href); atualizarMetaTag('twitter:title', noticiaSelecionada.titulo); atualizarMetaTag('twitter:description', noticiaSelecionada.subtitulo || 'Confira esta notícia no Ativa News'); atualizarMetaTag('twitter:image', noticiaSelecionada.imagem); atualizarMetaTag('twitter:card', 'summary_large_image'); // AVISO PARA O PRERENDER: A notícia carregou, pode tirar a foto agora! setTimeout(() => { window.prerenderReady = true; }, 800); } else if (!isPaginaNoticia && noticias.length > 0) { document.title = 'Ativa News - Informação com Credibilidade'; // AVISO PARA O PRERENDER: A página inicial (Home) carregou, pode tirar a foto! setTimeout(() => { window.prerenderReady = true; }, 800); } }, [noticiaSelecionada, noticias]); // FUNÇÃO PARA ATUALIZAR A URL AO CLICAR NUMA NOTÍCIA const abrirNoticia = (noticia) => { setNoticiaSelecionada(noticia); window.history.pushState({}, '', `?id=${noticia.id}`); window.scrollTo(0, 0); }; // FUNÇÃO PARA LIMPAR A URL AO VOLTAR PARA A HOME const voltarParaHome = () => { setNoticiaSelecionada(null); setMostrarContato(false); setMostrarAnuncie(false); setMostrarPrivacidade(false); window.history.pushState({}, '', window.location.pathname); window.scrollTo(0, 0); };