← back to Crazy News Channel
assets/daily-edition.js
102 lines
/* P24 Daily Edition (TK-12354) — renders window.P24_DAILY (daily-edition-data.js, built by
daily-edition/build.py) into #dailyEdition: today's TOP 6 with "Shadow Man" editorial-ink
cartoons, then ALL of today's news grouped by section. Zero dependencies; if the data file
is missing the section stays hidden (the rest of the page is unaffected). */
(function () {
"use strict";
var root = document.getElementById("dailyEdition");
var D = window.P24_DAILY;
if (!root || !D || !Array.isArray(D.top)) return;
function el(tag, attrs, kids) {
var n = document.createElement(tag);
if (attrs) Object.keys(attrs).forEach(function (k) {
if (k === "text") n.textContent = attrs[k];
else if (k === "cls") n.className = attrs[k];
else n.setAttribute(k, attrs[k]);
});
(kids || []).forEach(function (c) { if (c) n.appendChild(c); });
return n;
}
function when(iso) {
if (!iso) return "";
var d = new Date(iso);
if (isNaN(d)) return "";
return d.toLocaleString(undefined, { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" });
}
function ext(href, text, cls) {
return el("a", { href: href, target: "_blank", rel: "noopener noreferrer", cls: cls || "", text: text });
}
var edDate = new Date(D.date + "T12:00:00");
var dateLabel = edDate.toLocaleDateString(undefined, { weekday: "long", year: "numeric", month: "long", day: "numeric" });
var ageH = (Date.now() - new Date(D.built_at).getTime()) / 36e5;
var head = el("div", { cls: "de-head" }, [
el("p", { cls: "de-kicker", text: "Today's Edition · All the News, Daily" }),
el("h2", { id: "dailyEditionTitle", cls: "de-title", text: dateLabel }),
el("p", { cls: "de-meta" }, [
el("time", { datetime: D.built_at, title: D.built_at, text: "Updated " + when(D.built_at) }),
document.createTextNode(" · " + D.counts.all + " stories · top " + D.top.length + " illustrated by " + (D.illustrator || "Shadow Man"))
])
]);
root.appendChild(head);
if (ageH > 30) {
root.appendChild(el("p", { cls: "de-stale", role: "status",
text: "Heads up: this edition was last refreshed " + Math.round(ageH) + " hours ago." }));
}
// ---- Top 6
var grid = el("ol", { cls: "de-top", "aria-label": "Top " + D.top.length + " stories" });
D.top.forEach(function (s, i) {
var c = s.concept || {};
var fig = s.image
? el("img", { src: s.image, alt: "Editorial cartoon: " + (c.title || s.headline) + ". " + (c.caption || ""),
loading: i < 2 ? "eager" : "lazy", width: "1024", height: "657", decoding: "async" })
: el("div", { cls: "de-noimg", "aria-hidden": "true", text: "✒️" });
grid.appendChild(el("li", { cls: "de-card" }, [
el("figure", { cls: "de-fig" }, [
fig,
c.caption ? el("figcaption", { cls: "de-cap", text: "“" + c.caption + "”" }) : null
]),
el("div", { cls: "de-body" }, [
el("p", { cls: "de-rank" }, [
el("span", { cls: "de-num", text: String(i + 1) }),
el("span", { cls: "de-sec", text: s.section })
]),
el("h3", { cls: "de-h" }, [ext(s.url, s.headline)]),
el("p", { cls: "de-src", text: (s.outlet || "Source") + (s.published ? " · " + when(s.published) : "") })
])
]));
});
root.appendChild(grid);
// ---- All the news, grouped by section
var rest = D.all.filter(function (a) { return !a.top; });
var sections = [];
var bySec = {};
rest.forEach(function (a) {
if (!bySec[a.section]) { bySec[a.section] = []; sections.push(a.section); }
bySec[a.section].push(a);
});
var all = el("div", { cls: "de-all" }, [
el("h2", { cls: "de-all-h", text: "All the News · " + D.all.length + " stories today" })
]);
sections.forEach(function (sec) {
var ul = el("ul", { cls: "de-list" });
bySec[sec].forEach(function (a) {
ul.appendChild(el("li", null, [
ext(a.url, a.headline),
el("span", { cls: "de-src", text: " — " + (a.outlet || "") + (a.published ? " · " + when(a.published) : "") })
]));
});
all.appendChild(el("section", { cls: "de-sec-block", "aria-label": sec }, [
el("h3", { cls: "de-sec-h", text: sec + " (" + bySec[sec].length + ")" }), ul
]));
});
all.appendChild(el("p", { cls: "de-credit", text: "Headlines via " + (D.source || "the wire") +
", linking to each original publisher. Cartoons are original AI-generated satire signed Shadow Man; figures are invented, not real people." }));
root.appendChild(all);
root.hidden = false;
})();