/**
* Pure ESM changelog RSS document builder (used by generateStaticContent.mjs and re-exported from rss.tsx).
* @typedef {{ slug: string; title: string; sortDate: string; affectedProducts?: string[] }} ChangelogRssItemInput
*/
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc.js'
dayjs.extend(utc)
function xmlEncodeRss(str) {
if (str === undefined || str === null) return ''
return String(str)
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''')
}
function formatRssPubDate(isoOrDate) {
return `${dayjs(isoOrDate).utc().startOf('day').format('ddd, DD MMM YYYY HH:mm:ss')} +0000`
}
function buildItemsXml(sorted) {
return sorted
.map((e) => {
const encodedTitle = xmlEncodeRss(e.title)
const canonicalUrl = `https://supabase.com/changelog/${e.slug}`
const encodedCanonical = xmlEncodeRss(canonicalUrl)
const pubDate = formatRssPubDate(e.sortDate)
return ` -
${encodedCanonical}
${encodedTitle}
${encodedCanonical}
${pubDate}
`
})
.join('\n')
}
/**
* Converts a display label into a lowercase, URL-safe filename slug.
* e.g. "Edge Functions" → "edge-functions", "Data APIs" → "data-apis"
* @param {string} label
*/
export function labelToFileSlug(label) {
return label
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '')
}
/** @param {ChangelogRssItemInput[]} entries */
export function generateChangelogRssXml(entries) {
const sorted = [...entries].sort(
(a, b) => dayjs(b.sortDate).valueOf() - dayjs(a.sortDate).valueOf()
)
const lastBuildDate = sorted[0]?.sortDate
? formatRssPubDate(sorted[0].sortDate)
: formatRssPubDate(dayjs().toISOString())
return `
Supabase Changelog
https://supabase.com/changelog
Product updates and improvements from Supabase
en
${lastBuildDate}
${buildItemsXml(sorted)}
`
}
/**
* Generates a tag-filtered RSS feed.
* @param {ChangelogRssItemInput[]} allEntries - all entries, with `affected_products` display strings
* @param {{ displayLabel: string }} tag
*/
export function generateChangelogTagRssXml(allEntries, tag) {
const { displayLabel } = tag
const fileSlug = labelToFileSlug(displayLabel)
const filtered = allEntries.filter((e) =>
(e.affectedProducts ?? []).some(
(product) => product.toLowerCase() === displayLabel.toLowerCase()
)
)
const sorted = [...filtered].sort(
(a, b) => dayjs(b.sortDate).valueOf() - dayjs(a.sortDate).valueOf()
)
const lastBuildDate = sorted[0]?.sortDate
? formatRssPubDate(sorted[0].sortDate)
: formatRssPubDate(dayjs().toISOString())
const feedUrl = `https://supabase.com/changelog-rss/${fileSlug}.xml`
return `
Supabase Changelog · ${displayLabel}
https://supabase.com/changelog
${displayLabel} updates and improvements from Supabase
en
${lastBuildDate}
${buildItemsXml(sorted)}
`
}