Publish Container / docker (push) Successful in 15m20s
- Raise RSS description truncation from 220 → 800 chars so scripture references in episode descriptions are preserved - Global search now indexes Nuggets podcast episodes from /api/nuggets/episodes/all (title, subtitle, description via Fuse) - Scripture Index (/api/public/scripture-index) now extracts verse references from both main podcast and Nuggets RSS descriptions using a regex built from the shared BIBLE_BOOKS list; duplicate refs across sources are merged by the existing client-side dedup logic - Export fetchNuggetsEpisodes from nuggets.js for reuse Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
1.9 KiB
JavaScript
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() ?? ''
|
|
}
|
|
|
|
export 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 })
|
|
}
|
|
})
|
|
}
|