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)
const generateRssItem = (post: any): string => {
const xmlEncode = (str: string) => {
if (str === undefined || str === null) {
return ''
}
return str
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''')
}
const encodedTitle = xmlEncode(post.title)
const encodedPath = xmlEncode(post.path)
const encodedDescription = xmlEncode(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}
`
}
// we generate a main rss.xml flie as well as individual files for
// authors who publish under the `planetpg` tag
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('')}
`
}
}