import authors from 'lib/authors.json'
const dayjs = require('dayjs')
var utc = require('dayjs/plugin/utc')
var advancedFormat = require('dayjs/plugin/advancedFormat')
dayjs.extend(utc)
dayjs.extend(advancedFormat)
export function xmlEncodeRss(str: string | undefined | null): string {
if (str === undefined || str === null) {
return ''
}
return str
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''')
}
const generateRssItem = (post: any): string => {
const encodedTitle = xmlEncodeRss(post.title)
const encodedPath = xmlEncodeRss(post.path)
const encodedDescription = xmlEncodeRss(post.description)
const formattedDate = dayjs(post.date)
.utcOffset(0, true)
.startOf('day')
.format('ddd, DD MMM YYYY HH:mm:ss [-0700]')
return `-
https://supabase.com${encodedPath}
${encodedTitle}
https://supabase.com${encodedPath}
${encodedDescription}
${formattedDate}
`
}
export type ChangelogRssItemInput = {
title: string
slug: string
sortDate: string
affectedProducts?: string[]
}
/** Implemented in `./changelog-rss.mjs` (used by `scripts/generateStaticContent.mjs`). */
export { generateChangelogRssXml } from './changelog-rss.mjs'
// This utility generates RSS feeds for specialized content:
// 1. Customer stories RSS feed (customers-rss.xml) - used by pages/customers.tsx via getStaticProps
// 2. Author-specific PlanetPG RSS feeds (planetpg-{authorID}-rss.xml) - filtered feeds for individual authors
// 3. Changelog RSS (changelog-rss.xml) — built in generateStaticContent.mjs via ./changelog-rss.mjs
//
// Note: The main blog RSS feed (rss.xml) containing all blog posts is generated separately
// in generateStaticContent.mjs during the build process. This file is NOT used for the main blog feed.
//
// Usage:
// - Without authorID: Generates generic RSS feed (used for customer stories)
// - With authorID: Generates author-specific feed with custom title/description for PlanetPG authors
export const generateRss = (posts: any[], authorID?: string): string => {
const authorInfo = authors.find((item) => item.author_id === authorID)
const formattedDate = dayjs(posts[0].date)
.utcOffset(0, true)
.startOf('day')
.format('ddd, DD MMM YYYY HH:mm:ss [-0700]')
if (authorID) {
return `
'Postgres | Supabase Blog
https://supabase.com/blog
Latest Postgres news from ${authorInfo?.author} at Supabase
en
${formattedDate}
${posts.map(generateRssItem).join('')}
`
} else {
return `
Blog - Supabase
https://supabase.com
Latest news from Supabase
en
${formattedDate}
${posts.map(generateRssItem).join('')}
`
}
}