(function initACMediaRecords(global) { if (global.ACMediaRecords) return; function normalizeLink(link) { if (!link || typeof link !== "string") return ""; const trimmed = link.trim(); if (!trimmed) return ""; if (/^https?:\/\//i.test(trimmed)) return trimmed; if (/^at:\/\//i.test(trimmed)) return `https://pdsls.dev/${trimmed}`; if (/^[\w.-]+\.[a-z]{2,}([/?#].*)?$/i.test(trimmed)) return `https://${trimmed}`; return ""; } function recordFallbackLink(item) { if (!item?.uri || typeof item.uri !== "string") return ""; const atUri = item.uri.startsWith("at://") ? item.uri : `at://${item.uri.split("//")[1] || item.uri}`; return `https://pdsls.dev/${atUri}`; } function escapeHtml(value) { return String(value ?? "") .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } function buildFeedModalPayload(item, col, repoLabel, ago, title, primaryLink) { const recordLink = recordFallbackLink(item); const safePrimaryLink = normalizeLink(primaryLink); const safeCode = item?.code ? encodeURIComponent(String(item.code)) : ""; let iframeUrl = ""; let previewHtml = ""; let extraHtml = ""; switch (col.label) { case "painting": if (safeCode) { previewHtml = ``; } break; case "kidlisp": if (safeCode) { previewHtml = ``; } if (item?.source) { extraHtml = `
${escapeHtml(String(item.source).slice(0, 1200))}
`; } break; case "mood": if (item?.mood) { extraHtml = `
${escapeHtml(item.mood)}
`; } break; case "news": { const newsUrl = safePrimaryLink || "https://news.aesthetic.computer"; iframeUrl = newsUrl; if (item?.body) { extraHtml = `
${escapeHtml(String(item.body).slice(0, 1800))}
`; } break; } case "paper": iframeUrl = safePrimaryLink; break; default: iframeUrl = ""; } const metadata = [ ["Type", col.label], ["When", ago || "recent"], ["From", repoLabel || "unknown"], ["Rkey", item?.uri ? String(item.uri).split("/").pop() : ""], ] .filter((entry) => entry[1]) .map((entry) => `
${escapeHtml(entry[0])}: ${escapeHtml(entry[1])}
`) .join(""); const rawRecord = escapeHtml(JSON.stringify(item, null, 2)); const bodyHtml = ` ${previewHtml} ${extraHtml}
${metadata}
Raw record
${rawRecord}
`; const actions = []; if (safePrimaryLink) actions.push({ label: "Open Link", url: safePrimaryLink }); if (col.label === "news") actions.push({ label: "Open News Site", url: "https://news.aesthetic.computer" }); if (recordLink) actions.push({ label: "View Record", url: recordLink }); const seen = new Set(); const dedupedActions = actions.filter((action) => { if (seen.has(action.url)) return false; seen.add(action.url); return true; }); return { title: `${col.icon} ${title || col.label}`, subtitle: `${col.label} · ${ago || "recent"} · ${repoLabel || "unknown"}`, bodyHtml, iframeUrl, actions: dedupedActions, }; } global.ACMediaRecords = { buildFeedModalPayload, escapeHtml, normalizeLink, recordFallbackLink, }; })(window);