Últimas notícias
Cobertura contínua com foco em descoberta, contexto e impacto científico real.
Arquivo editorial
Todas as matérias disponíveis no portal.
Busca
${tr('noSearch')}
${tr('trySearch')}
`; } else { empty.classList.add('hidden'); } markNav(''); activatePage('search'); updateMetaStatic('search'); } // ── Navigation helpers ───────────────────────────────────────────────────── function activatePage(page) { currentPage = page; document.querySelectorAll('.page').forEach(el => el.classList.remove('active')); const map = { home:'pageHome', article:'pageArticle', archive:'pageArchive', about:'pageAbout', standards:'pageStandards', search:'pageSearch' }; const el = document.getElementById(map[page]); if (el) el.classList.add('active'); window.scrollTo({ top: 0, behavior: 'smooth' }); } function markNav(which) { ['navHome','navArchive','navAbout','navStandards'].forEach(id => document.getElementById(id).classList.remove('on')); const map = { home:'navHome', archive:'navArchive', about:'navAbout', standards:'navStandards' }; if (map[which]) document.getElementById(map[which]).classList.add('on'); } function setCategory(category, btn) { currentCategory = category || 'all'; if (btn) syncCategoryButtons(btn); if (currentPage === 'archive') renderArchive(); else renderHome(); } function syncCategoryButtons(activeBtn) { document.querySelectorAll('.cat-pill').forEach(btn => btn.classList.remove('on')); if (activeBtn) { activeBtn.classList.add('on'); return; } const target = document.querySelector(`.cat-pill[data-cat="${CSS.escape(currentCategory)}"]`) || document.querySelector('.cat-pill[data-cat="all"]'); if (target) target.classList.add('on'); } function openPage(page) { if (page === 'archive') { history.replaceState({}, '', pageUrl('archive')); renderArchive(); } else if (page === 'about') { history.replaceState({}, '', pageUrl('about')); renderAbout(); } else if (page === 'standards') { history.replaceState({}, '', pageUrl('standards')); renderStandards(); } else goHome(); } function goHome() { history.replaceState({}, '', SITE.baseUrl); renderHome(); } function openArticle(slug) { const post = DB.find(item => item.slug === slug); if (post) history.pushState({}, '', getURLForArticle(post)); renderArticle(slug); } function handleSearchInput(value) { clearTimeout(searchTimer); if (!value.trim()) { if (currentPage === 'search') goHome(); return; } searchTimer = setTimeout(() => renderSearch(value.trim()), 220); } function setLanguage(lang) { currentLang = lang === 'en' ? 'en' : 'pt'; localStorage.setItem('cw_lang', currentLang); applyUIStrings(); rerenderCurrentView(); } function applyUIStrings() { document.documentElement.lang = currentLang === 'en' ? 'en-US' : 'pt-BR'; const ids = { logoSub:'logoSub', navHome:'home', navArchive:'archive', navAbout:'about', navStandards:'standards', methodBtn:'methodology', adsBtn:'advertise', updateBtnLabel:'update', tickerBadge:'ticker', latestSectionTitle:'latestTitle', latestSectionKicker:'latestKicker', archiveLinkTop:'archiveLink', trendingWidgetTitle:'trending', latestUpdatesTitle:'latestUpdatesTitle', topicNavTitle:'topicNavTitle', quickLinksTitle:'quickLinksTitle', archivePicksTitle:'archivePicksTitle', archiveTitle:'archiveTitle', archiveKicker:'archiveKicker', searchTitle:'searchTitle', footerDescription:'footerDescription', footerNavTitle:'footerNavTitle', footerAdvertise:'advertise', footerMediaKit:'mediaKit', footerSourcesTitle:'footerSourcesTitle', footerFeed:'footerFeed', footerPrivacy:'privacy', footerTerms:'terms', footerSitemap:'footerSitemap', footerCorrections:'footerCorrections', footerBottomLeft:'footerBottomLeft', footerBottomCenter:'footerBottomCenter', footerBottomRight:'footerBottomRight', newsletterTitle:'newsletterTitle', newsletterDescription:'newsletterDescription', newsletterButton:'newsletterButton', newsletterNote:'newsletterNote', newsletterButton:'newsletterButton' }; for (const [id, key] of Object.entries(ids)) { const el = document.getElementById(id); if (el) el.textContent = tr(key); } document.getElementById('topbarCopy').innerHTML = tr('topbarCopy'); const si = document.getElementById('searchInput'); if (si) si.placeholder = tr('searchPlaceholder'); const nl = document.getElementById('newsletterLabel'); if (nl) nl.textContent = tr('newsletterLabel'); const ne = document.getElementById('newsletterEmail'); if (ne) ne.placeholder = tr('newsletterPlaceholder'); document.querySelectorAll('.cat-pill').forEach(btn => { const cat = btn.dataset.cat; btn.textContent = cat === 'all' ? tr('allCategories') : prettyCategory(cat); }); document.getElementById('langPt').classList.toggle('on', currentLang==='pt'); document.getElementById('langEn').classList.toggle('on', currentLang==='en'); updateRigSyncBannerLanguage(); updateLastUpdatedLabel(); } const RIGSYNC_BANNER_COPY = { pt: { eyebrow: 'Para quem trabalha embarcado', text: 'Escala, folgas e ganho estimado para quem trabalha embarcado ou em plataformas.', cta: 'Ver app', close: 'Fechar anúncio' }, en: { eyebrow: 'Built for offshore rotations', text: 'Roster, time off and estimated earnings for offshore crews and oilfield schedules.', cta: 'Get app', close: 'Close ad' } }; function updateRigSyncBannerLanguage() { const copy = RIGSYNC_BANNER_COPY[currentLang] || RIGSYNC_BANNER_COPY.pt; const eyebrow = document.getElementById('rigsyncBannerEyebrow'); const text = document.getElementById('rigsyncBannerText'); const cta = document.getElementById('rigsyncBannerCta'); const close = document.getElementById('rigsyncBannerClose'); const banner = document.getElementById('rigsyncBanner'); if (eyebrow) eyebrow.textContent = copy.eyebrow; if (text) text.textContent = copy.text; if (cta) cta.textContent = copy.cta; if (close) close.setAttribute('aria-label', copy.close); if (banner) banner.setAttribute('aria-label', currentLang === 'en' ? 'RigSync Calendar app promotion' : 'Promoção do aplicativo RigSync Calendar'); } function syncRigSyncBannerOffset() { const banner = document.getElementById('rigsyncBanner'); if (!banner) return; const cookie = document.getElementById('cookieBanner'); const visible = cookie && cookie.classList.contains('show'); const base = window.innerWidth <= 780 ? 12 : 18; const extra = visible ? cookie.offsetHeight + 16 : 0; banner.style.bottom = `${base + extra}px`; } function initRigSyncBanner() { const banner = document.getElementById('rigsyncBanner'); const close = document.getElementById('rigsyncBannerClose'); if (!banner || !close) return; try { if (localStorage.getItem('cw_rigsync_banner_dismissed') === '1') { banner.remove(); return; } } catch (e) {} updateRigSyncBannerLanguage(); syncRigSyncBannerOffset(); close.addEventListener('click', () => { banner.classList.remove('show'); window.setTimeout(() => banner.remove(), 220); try { localStorage.setItem('cw_rigsync_banner_dismissed', '1'); } catch (e) {} }); window.addEventListener('resize', syncRigSyncBannerOffset, { passive: true }); const cookie = document.getElementById('cookieBanner'); if (cookie && typeof MutationObserver !== 'undefined') { const observer = new MutationObserver(syncRigSyncBannerOffset); observer.observe(cookie, { attributes: true, attributeFilter: ['class', 'style'] }); } window.setTimeout(() => banner.classList.add('show'), 850); } function updateLastUpdatedLabel() { const latest = DB[0]; const stamp = latest ? `${currentLang==='en'?(latest.date_en||latest.date):(latest.date_pt||latest.date)} · ${currentLang==='en'?(latest.time_en||latest.time):(latest.time_pt||latest.time)}` : tr('latestFeed'); const el = document.getElementById('lastUpdatedLabel'); if (el) el.textContent = `${tr('lastUpdatedPrefix')} ${stamp}`; } function showToast(message) { const toast = document.getElementById('toast'); toast.textContent = message; toast.classList.add('show'); clearTimeout(toastTimer); toastTimer = setTimeout(() => toast.classList.remove('show'), 3200); } function refreshFeed() { const btn = document.getElementById('updateBtn'); bumpHeroRotationSeed(); btn.classList.add('loading'); btn.disabled = true; fetch(`posts.js?cb=${Date.now()}`, { cache:'no-store' }) .then(resp => { if (!resp.ok) throw new Error('fetch failed'); return resp.text(); }) .then(js => { const sandboxWindow = {}; Function('window', js + '; return window.postsData;')(sandboxWindow); if (Array.isArray(sandboxWindow.postsData) && sandboxWindow.postsData.length) { DB = mergePostCollections(sandboxWindow.postsData, DB); frontLayoutCache.clear(); persistArchiveCache(); updateLastUpdatedLabel(); rerenderCurrentView(); showToast(tr('updateDone')); } else { rerenderCurrentView(); showToast(tr('updateDone')); } }) .catch(() => { rerenderCurrentView(); showToast(tr('updateFail')); }) .finally(() => { btn.classList.remove('loading'); btn.disabled = false; }); } function copyArticleLink() { const post = DB.find(item => item.slug === currentArticleSlug); const url = post ? getURLForArticle(post) : location.href; navigator.clipboard.writeText(url).then(() => showToast(tr('copied'))).catch(() => showToast(url)); } function handleNewsletterSubmit(event) { event.preventDefault(); const input = document.getElementById('newsletterEmail'); const email = input.value.trim(); if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { showToast(tr('newsletterInvalid')); input.focus(); return; } localStorage.setItem('cw_newsletter_email', email); input.value = ''; showToast(tr('newsletterSuccess')); } function loadSavedNewsletterEmail() { const saved = localStorage.getItem('cw_newsletter_email'); if (saved) { const el = document.getElementById('newsletterEmail'); if (el) el.value = saved; } } const CONSENT_KEY = 'cw_cookie_consent'; /* Mapeia os 3 estados para os sinais do Consent Mode v2. 'full' → analytics + anúncios personalizados 'analytics' → só analytics, anúncios não-personalizados 'denied' → tudo desligado */ function _consentSignals(mode) { const full = mode === 'full'; const analytics = mode === 'full' || mode === 'analytics'; return { analytics_storage: analytics ? 'granted' : 'denied', ad_storage: full ? 'granted' : 'denied', ad_user_data: full ? 'granted' : 'denied', ad_personalization: full ? 'granted' : 'denied' }; } function setCookieConsent(mode) { // mode: 'full' | 'analytics' | 'denied' try { localStorage.setItem(CONSENT_KEY, mode); } catch (e) {} if (typeof gtag === 'function') gtag('consent', 'update', _consentSignals(mode)); const banner = document.getElementById('cookieBanner'); if (banner) banner.classList.remove('show'); } function initCookieBanner() { let saved = null; try { saved = localStorage.getItem(CONSENT_KEY); } catch (e) {} const banner = document.getElementById('cookieBanner'); if (!banner) return; const validStates = ['full', 'analytics', 'denied', 'granted']; // 'granted' = estado legado, tratar como 'analytics' if (validStates.includes(saved)) { const normalized = saved === 'granted' ? 'analytics' : saved; if (typeof gtag === 'function') gtag('consent', 'update', _consentSignals(normalized)); // Migra silenciosamente o valor legado if (saved === 'granted') { try { localStorage.setItem(CONSENT_KEY, 'analytics'); } catch (e) {} } banner.classList.remove('show'); return; } banner.classList.add('show'); } // ── SEO / Meta ───────────────────────────────────────────────────────────── function updateMetaHome() { const title = currentLang==='en' ? SITE.homeTitleEn : SITE.homeTitlePt; const description = currentLang==='en' ? SITE.homeDescriptionEn : SITE.homeDescriptionPt; updateMetaCommon(title, description, SITE.baseUrl, IMG.pillars, null, { robots: 'index,follow,max-image-preview:large,max-snippet:-1,max-video-preview:-1', newsKeywords: 'astronomia, astrofísica, cosmologia, ciência, espaço' }); } function updateMetaStatic(page) { const titles = { about: currentLang==='en'?'About Cosmos Week':'Sobre o Cosmos Week', archive: currentLang==='en'?'Editorial archive':'Arquivo editorial', standards: currentLang==='en'?'Editorial standards':'Padrões editoriais', search: currentLang==='en'?'Search':'Busca' }; const descriptions = { about: currentLang==='en'?'About the editorial ambition and scope of Cosmos Week.':'Sobre a ambição editorial e o escopo do Cosmos Week.', archive: currentLang==='en'?'The complete archive of stories currently available.':'O arquivo completo das matérias disponíveis.', standards: currentLang==='en'?'Methodology, source labeling and editorial safeguards.':'Metodologia, rotulagem de fonte e salvaguardas editoriais.', search: currentLang==='en'?'Search results inside Cosmos Week.':'Resultados de busca dentro do Cosmos Week.' }; updateMetaCommon(`${titles[page]} — ${SITE.title}`, descriptions[page], pageUrl(page), IMG.pillars, null, { robots: page === 'search' ? 'noindex,follow' : 'index,follow', newsKeywords: 'Notícias Científicas, astronomia, astrofísica, cosmologia' }); } function updateMetaArticle(post) { const title = `${textFor(post,'title')} — ${SITE.title}`; const description = textFor(post,'excerpt'); const url = getURLForArticle(post); const keywords = keywordListFor(post); const jsonLd = [ { '@context':'https://schema.org','@type':'NewsMediaOrganization', name:SITE.title, url:SITE.baseUrl, logo:{'@type':'ImageObject',url:IMG.pillars} }, { '@context':'https://schema.org','@type':'BreadcrumbList', itemListElement:[ {'@type':'ListItem',position:1,name:currentLang==='en'?'Home':'Início',item:SITE.baseUrl}, {'@type':'ListItem',position:2,name:prettyCategory(post.cat),item:`${SITE.baseUrl}?category=${encodeURIComponent(post.cat)}`}, {'@type':'ListItem',position:3,name:textFor(post,'title'),item:url} ]}, { '@context':'https://schema.org','@type':'NewsArticle', headline:textFor(post,'title'), description, image:[primaryImage(post)], datePublished:post.publishedIso, dateModified:post.lastModifiedIso||post.publishedIso, inLanguage:currentLang==='en'?'en':'pt-BR', isAccessibleForFree:true, articleSection:prettyCategory(post.cat), keywords, author:[{'@type':'Organization',name:tr('newsroom')}], publisher:{'@type':'Organization',name:SITE.title,logo:{'@type':'ImageObject',url:IMG.pillars}}, mainEntityOfPage:url, about:keywords.map(k => ({'@type':'Thing',name:k})) } ]; updateMetaCommon(title, description, url, primaryImage(post), jsonLd, { robots: 'index,follow,max-image-preview:large,max-snippet:-1,max-video-preview:-1', newsKeywords: keywords.join(', '), published: post.publishedIso, modified: post.lastModifiedIso || post.publishedIso }); } function updateMetaCommon(title, description, url, image, articleJsonLd, options = {}) { document.title = title; document.querySelector('meta[name="description"]').setAttribute('content', description); document.querySelector('meta[property="og:title"]').setAttribute('content', title); document.querySelector('meta[property="og:description"]').setAttribute('content', description); document.querySelector('meta[property="og:url"]').setAttribute('content', url); document.querySelector('meta[property="og:image"]').setAttribute('content', image); document.querySelector('meta[name="twitter:title"]').setAttribute('content', title); document.querySelector('meta[name="twitter:description"]').setAttribute('content', description); document.querySelector('meta[name="twitter:image"]').setAttribute('content', image); document.getElementById('canonicalLink').setAttribute('href', url); document.getElementById('robotsMeta').setAttribute('content', options.robots||'index,follow'); document.getElementById('newsKeywordsMeta').setAttribute('content', options.newsKeywords||'astronomia, ciência'); document.getElementById('articlePublishedMeta').setAttribute('content', options.published||''); document.getElementById('articleModifiedMeta').setAttribute('content', options.modified||options.published||''); document.getElementById('siteJsonLd').textContent = JSON.stringify(articleJsonLd || { '@context':'https://schema.org','@type':'WebSite', name:SITE.title, url:SITE.baseUrl, description }); } function rerenderCurrentView() { if (currentPage==='article' && currentArticleSlug) renderArticle(currentArticleSlug); else if (currentPage==='archive') renderArchive(); else if (currentPage==='about') renderAbout(); else if (currentPage==='standards') renderStandards(); else if (currentPage==='search') { const q = document.getElementById('searchInput').value.trim(); if (q) renderSearch(q); else renderHome(); } else renderHome(); } function parseRoute() { const params = new URLSearchParams(window.location.search); const article = params.get('article'); const page = params.get('page'); if (article) { renderArticle(article); return; } if (page==='arquivo') { renderArchive(); return; } if (page==='sobre') { renderAbout(); return; } if (page==='padroes') { renderStandards(); return; } renderHome(); } // Reading progress window.addEventListener('scroll', () => { const max = document.documentElement.scrollHeight - window.innerHeight; const ratio = max > 0 ? (window.scrollY / max) * 100 : 0; document.getElementById('readingProgress').style.width = `${ratio}%`; }, { passive: true }); window.addEventListener('popstate', parseRoute); document.addEventListener('DOMContentLoaded', () => { applyUIStrings(); loadSavedNewsletterEmail(); initCookieBanner(); initRigSyncBanner(); persistArchiveCache(); parseRoute(); setTimeout(() => showToast(tr('welcome')), 900); });