/* WDCM consolidated client-side widgets (v2, Sep 2026) Modules: wdcm-gps (badge), wdcm-related, hero pin (latest Rod/Morganne feature, <=10 days), wdcm-homefix. Hosted on Ghost file store so it doesn't consume the 64KB codeinjection cap. */ (function () { var KEY = '6a3e40e14a8c49d7da3546ac98'; /* ---------- styles ---------- */ var css = [ /* preferred-source badge */ '.wdcm-gps{background:#0D1B2A;display:flex;flex-direction:column;align-items:center;gap:6px;padding:22px 16px 10px;text-align:center;font-family:Inter,system-ui,sans-serif}', '.wdcm-gps__k{color:#C9A84C;font-weight:600;font-size:12px;letter-spacing:.08em;text-transform:uppercase}', '.wdcm-gps a{display:inline-flex;align-items:center;gap:11px;background:#C9A84C;color:#0D1B2A;font-weight:700;font-size:14px;line-height:1;text-decoration:none;padding:10px 16px 10px 11px;border-radius:9px;border:1px solid #d8bd6a;box-shadow:0 2px 10px rgba(0,0,0,.3);transition:transform .12s,box-shadow .12s}', '.wdcm-gps a:hover{transform:translateY(-1px);box-shadow:0 5px 16px rgba(0,0,0,.4)}', '.wdcm-gps a:focus-visible{outline:2px solid #fff;outline-offset:2px}', '.wdcm-gps__g{width:26px;height:26px;background:#fff;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;flex:none}', '.wdcm-gps__g svg{width:16px;height:16px;display:block}', '.wdcm-gps__t{display:flex;flex-direction:column;text-align:left}', '.wdcm-gps__t small{font-weight:500;font-size:11px;opacity:.75;margin-top:2px}', /* related posts */ '.wdcm-related{max-width:720px;margin:44px auto 8px;padding:0 20px;font-family:Inter,system-ui,sans-serif}', '.wdcm-related__h{font-size:13px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:#9A6B15;border-bottom:2px solid #0D1B2A;padding-bottom:8px;margin:0 0 4px}', '.wdcm-related__list{list-style:none;margin:0;padding:0}', '.wdcm-related__list li{border-bottom:1px solid #ececec}', '.wdcm-related__list a{display:flex;justify-content:space-between;gap:16px;align-items:baseline;padding:13px 2px;color:#1A1410;text-decoration:none;transition:color .12s ease}', '.wdcm-related__list a:hover{color:#9A6B15}', '.wdcm-related__t{font-size:16px;font-weight:600;line-height:1.35}', '.wdcm-related__d{font-size:12px;color:#8a8a8a;white-space:nowrap;font-variant-numeric:tabular-nums}', /* hero headline cap (desktop only) */ '@media(min-width:900px){.top-story-title{font-size:2.5rem!important;line-height:1.14!important}}' ].join(''); if (!document.getElementById('wdcm-widgets-css')) { var st = document.createElement('style'); st.id = 'wdcm-widgets-css'; st.textContent = css; (document.head || document.documentElement).appendChild(st); } /* ---------- 1) Google Preferred Source badge (footer) ---------- */ function badge() { if (document.querySelector('.wdcm-gps')) return; var foot = document.querySelector('footer,.site-footer,.gh-foot'); if (!foot) return; var w = document.createElement('div'); w.className = 'wdcm-gps'; w.innerHTML = 'Get more of us in Google Top Stories' + '' + '' + 'Add us as a Preferred SourceFollow Washington DC Magazine on Google'; foot.insertBefore(w, foot.firstChild); } /* ---------- 2) Related posts (article pages) ---------- */ function fmt(d) { try { return new Date(d).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); } catch (e) { return ''; } } function isPost() { return document.body.classList.contains('post-template') || !!document.querySelector('article.post-full'); } function slug() { var p = location.pathname.split('/').filter(Boolean); return p[p.length - 1] || ''; } function related() { if (!isPost() || document.querySelector('.wdcm-related')) return; var art = document.querySelector('article.post-full') || document.querySelector('main article'); if (!art) return; var api = '/ghost/api/content/posts/'; fetch(api + 'slug/' + slug() + '/?key=' + KEY + '&include=tags&fields=id,title').then(function (r) { return r.json(); }).then(function (j) { var post = (j.posts || [])[0]; if (!post || !post.tags || !post.tags.length) return; var tags = post.tags.map(function (t) { return t.slug; }).filter(function (s) { return s.indexOf('hash-') !== 0; }).slice(0, 3); if (!tags.length) return; var filter = 'tag:[' + tags.join(',') + ']+id:-' + post.id; return fetch(api + '?key=' + KEY + '&limit=4&order=' + encodeURIComponent('published_at desc') + '&fields=title,url,published_at&filter=' + encodeURIComponent(filter)).then(function (r) { return r.json(); }).then(function (j2) { var posts = (j2.posts || []).slice(0, 4); if (!posts.length || document.querySelector('.wdcm-related')) return; var wrap = document.createElement('section'); wrap.className = 'wdcm-related'; var h = document.createElement('div'); h.className = 'wdcm-related__h'; h.textContent = 'More from Washington DC Magazine'; wrap.appendChild(h); var ul = document.createElement('ul'); ul.className = 'wdcm-related__list'; posts.forEach(function (p) { var li = document.createElement('li'); var a = document.createElement('a'); a.href = p.url; var t = document.createElement('span'); t.className = 'wdcm-related__t'; t.textContent = p.title; var d = document.createElement('span'); d.className = 'wdcm-related__d'; d.textContent = fmt(p.published_at); a.appendChild(t); a.appendChild(d); li.appendChild(a); ul.appendChild(li); }); wrap.appendChild(ul); art.appendChild(wrap); }); }).catch(function () { }); } /* ---------- 3) Homepage hero pin (latest Rod/Morganne feature, if recent) ---------- */ function isHome() { return location.pathname.replace(/\/+$/, '') === ''; } function longdate(d) { try { return new Date(d).toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' }); } catch (e) { return ''; } } function normPath(h) { try { return new URL(h, location.origin).pathname.replace(/\/+$/, ''); } catch (e) { return (h || '').replace(/\/+$/, ''); } } function heropin() { if (!isHome()) return; var sec = document.querySelector('.top-story-section'); if (!sec || sec.dataset.wdcmPin) return; sec.dataset.wdcmPin = '1'; /* claim synchronously so the repeated run() passes don't double-fetch */ var api = '/ghost/api/content/posts/'; var filter = 'authors:[rod,morganne]'; fetch(api + '?key=' + KEY + '&limit=1&order=' + encodeURIComponent('published_at desc') + '&filter=' + encodeURIComponent(filter) + '&fields=title,slug,feature_image,custom_excerpt,excerpt,published_at,reading_time&include=authors,tags') .then(function (r) { return r.json(); }) .then(function (j) { var p = (j.posts || [])[0]; if (!p) return; /* recency gate: only pin a human feature while it is fresh; otherwise leave the theme's news hero */ if (Date.now() - new Date(p.published_at).getTime() > 10 * 864e5) return; var titleA = sec.querySelector('.top-story-title a'); if (!titleA) return; var want = '/' + p.slug + '/'; if (normPath(titleA.getAttribute('href')) === normPath(want)) return; /* already the hero */ var img = sec.querySelector('.top-story-image'); if (img && p.feature_image) img.style.backgroundImage = "url('" + p.feature_image + "')"; var badge = sec.querySelector('.category-badge'), pt = null, i; if (p.tags) { for (i = 0; i < p.tags.length; i++) { var sl = p.tags[i].slug; if (sl.indexOf('hash-') !== 0 && sl !== 'editors-pick') { pt = p.tags[i]; break; } } } if (badge && pt) badge.textContent = pt.name; /* keep the theme's badge class so it stays styled */ titleA.textContent = p.title; titleA.setAttribute('href', want); var deck = sec.querySelector('.top-story-deck'); if (deck) deck.textContent = (p.custom_excerpt || p.excerpt || '').trim(); var byl = sec.querySelector('.top-story-byline'); if (byl) { var au = (p.authors && p.authors[0]) ? p.authors[0].name : ''; var parts = ['By ' + au, longdate(p.published_at)]; if (p.reading_time) parts.push(p.reading_time + ' min read'); byl.innerHTML = parts.map(function (x) { return '' + x + ''; }).join('·'); } var link = sec.querySelector('.top-story-link'); if (link) link.setAttribute('href', want); }) .catch(function () { sec.dataset.wdcmPin = ''; /* allow a later retry on network error */ }); } /* ---------- 4) Homepage fixes ---------- */ function homefix() { var i, sp = document.querySelectorAll('span'); for (i = 0; i < sp.length; i++) { var s = sp[i]; if (!s.children.length && s.textContent.indexOf('min read min read') > -1) { s.textContent = s.textContent.replace(/min read min read/g, 'min read'); } } var wt = document.querySelectorAll('.widget-title'); for (i = 0; i < wt.length; i++) { if (wt[i].textContent.trim() === 'Upcoming DC Events') { wt[i].textContent = 'DC Events'; } } var hs = document.querySelectorAll('h4'), h = null; for (i = 0; i < hs.length; i++) { if (/amazon picks/i.test(hs[i].textContent)) { h = hs[i]; break; } } if (h) { var n = h; for (var k = 0; k < 6; k++) { if (n.parentElement) n = n.parentElement; if (/shop on amazon/i.test(n.textContent) && n.getBoundingClientRect().height > 120) break; } var foot = document.querySelector('footer,.site-footer'); if (foot && n && n !== document.body && !n.dataset.wdcmMoved && foot.parentElement) { n.dataset.wdcmMoved = '1'; foot.parentElement.insertBefore(n, foot); } } } function run() { try { badge(); } catch (e) { } try { related(); } catch (e) { } try { heropin(); } catch (e) { } try { homefix(); } catch (e) { } } function go() { run(); setTimeout(run, 900); setTimeout(run, 2400); } if (document.readyState !== 'loading') go(); else document.addEventListener('DOMContentLoaded', go); })();