Brasil

Categoria

Carregando notícias...
`; async function loadCategoryData() { if(isFetching) return; isFetching = true; const btnLoad = document.getElementById('nj-btn-loadmore'); try { if(!categoryId) { const catRes = await fetch(`${SITE_URL}/wp-json/wp/v2/categories?slug=${CATEGORY_SLUG}`); const catData = await catRes.json(); if(!catData.length) throw new Error('Categoria não encontrada'); categoryId = catData[0].id; } btnLoad.innerText = "Carregando..."; const res = await fetch(`${SITE_URL}/wp-json/wp/v2/posts?_embed&categories=${categoryId}&per_page=${POSTS_PER_PAGE}&page=${currentPage}`); if (!res.ok) { btnLoad.innerText = "Fim das notícias"; btnLoad.disabled = true; return; } const posts = await res.json(); document.getElementById('nj-page-loading').classList.add('nj-hidden'); if (posts.length === 0) { btnLoad.innerText = "Fim das notícias"; btnLoad.disabled = true; return; } let listPosts = posts; if (currentPage === 1 && posts.length >= 3) { const principal = posts[0]; const sec1 = posts[1]; const sec2 = posts[2]; listPosts = posts.slice(3); const heroHtml = `
${CATEGORY_NAME}

${decodeHTML(principal.title.rendered)}

${[sec1, sec2].map(p => `
${CATEGORY_NAME}

${decodeHTML(p.title.rendered)}

`).join('')}
`; const heroContainer = document.getElementById('nj-hero-container'); heroContainer.innerHTML = heroHtml; heroContainer.classList.remove('nj-hidden'); } if (listPosts.length > 0) { const listHtml = listPosts.map(renderFeedItem).join(''); const feedContainer = document.getElementById('nj-feed-container'); feedContainer.insertAdjacentHTML('beforeend', listHtml); feedContainer.classList.remove('nj-hidden'); } currentPage++; btnLoad.innerText = "Carregar Mais Notícias"; btnLoad.classList.remove('nj-hidden'); } catch(e) { console.error("Erro na Categoria:", e); if(currentPage === 1) document.getElementById('nj-page-loading').innerText = "Não foi possível carregar esta categoria."; btnLoad.innerText = "Erro ao carregar. Tente novamente."; } finally { isFetching = false; } } loadCategoryData(); document.getElementById('nj-btn-loadmore').addEventListener('click', loadCategoryData); })();