const SITE_URL = 'https://stacker.news' const SITE_TITLE = 'Stacker News' const SITE_SUBTITLE = 'Like Hacker News, but we pay you Bitcoin.' function escapeXml (unsafe) { return unsafe.replace(/[<>&'"]/g, function (c) { switch (c) { case '<': return '<' case '>': return '>' case '&': return '&' case '\'': return ''' case '"': return '"' } }) } const generateRssItem = (item) => { const guid = `${SITE_URL}/items/${item.id}` const link = item.url || guid return ` ${SITE_URL}/items/${item.id} ${escapeXml(item.title)} ${escapeXml(link)} ${guid} Comments]]> ${new Date(item.createdAt).toUTCString()} ` } export default function generateRssFeed (items) { const itemsList = items.map(generateRssItem) return ` ${SITE_TITLE} ${SITE_URL} ${SITE_SUBTITLE} en ${new Date().toUTCString()} ${itemsList.join('')} ` }