Files
Siteforge/server/routes/nuggets.js
T
nmemmertandClaude Sonnet 5 31e79ad542
Publish Container / docker (push) Successful in 14m16s
Add Verse By Verse: Nuggets sub-show with editable hosts and RSS feed
New /nuggets page for the companion show, linked from the Episodes nav
dropdown. Hosts (name, role, bio, photo) show in a left column with the
episode list on the right — latest episode featured, rest below.
Episodes are pulled from an admin-configurable RSS feed URL (empty by
default, shows "coming soon" until set) rather than hardcoded like the
main show's feed, since the show doesn't have one yet.

Everything is editable in /admin under a new Nuggets section: Show
Settings (title, tagline, description, podcast art, RSS/platform URLs)
and Hosts (add freely; removing a host archives them instead of
deleting — kept on record and restorable, never lost).

Extracted the RSS item-parsing logic shared with the main show's feed
(server/routes/episodes.js) into server/rss-helpers.js so both feeds
use the same parser instead of duplicating it.

Also fixes the local Vite dev server not proxying /uploads/* to the
backend — it was silently serving the SPA shell (200, text/html)
instead of the actual file, so any admin-uploaded image (podcast art,
host photos, etc.) appeared broken in local dev only.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Yvx4rPVy2HWe7ubuk3X3J
2026-09-07 14:27:52 -04:00

63 lines
1.9 KiB
JavaScript

import { parseRssItems } from '../rss-helpers.js'
import { state } from '../state.js'
let cache = null // { url, episodes }
let cacheAt = 0
const CACHE_TTL = 30 * 60 * 1000
function feedUrl() {
return state.cachedSiteContent?.nuggets?.rssFeedUrl?.trim() ?? ''
}
async function fetchNuggetsEpisodes() {
const url = feedUrl()
if (!url) { cache = null; return [] }
const now = Date.now()
if (cache && cache.url === url && (now - cacheAt) < CACHE_TTL) {
return cache.episodes
}
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), 8000)
try {
const response = await fetch(url, { signal: controller.signal })
clearTimeout(timeout)
if (!response.ok) throw new Error(`RSS fetch failed: ${response.status}`)
const xml = await response.text()
const episodes = parseRssItems(xml)
cache = { url, episodes }
cacheAt = now
return episodes
} catch (err) {
clearTimeout(timeout)
// Serve stale cache for this same URL rather than a hard failure, if we have one.
if (cache && cache.url === url) return cache.episodes
throw err
}
}
export function register(app) {
app.get('/api/nuggets/episodes', async (_req, res) => {
const configured = Boolean(feedUrl())
try {
const episodes = await fetchNuggetsEpisodes()
res.json({ episodes: episodes.slice(0, 6), configured })
} catch (err) {
console.error('[nuggets/episodes] RSS fetch error:', err.message)
res.json({ episodes: [], configured })
}
})
app.get('/api/nuggets/episodes/all', async (_req, res) => {
const configured = Boolean(feedUrl())
try {
const episodes = await fetchNuggetsEpisodes()
res.json({ episodes, configured })
} catch (err) {
console.error('[nuggets/episodes/all] RSS fetch error:', err.message)
res.json({ episodes: [], configured })
}
})
}