Skip to content

Instantly share code, notes, and snippets.

@tashima42
Last active June 17, 2022 22:11
Show Gist options
  • Save tashima42/ba7e338fccd3c6c0c86f7ca4ff9e2615 to your computer and use it in GitHub Desktop.
Save tashima42/ba7e338fccd3c6c0c86f7ca4ff9e2615 to your computer and use it in GitHub Desktop.
RSS 2.0 generator POC
function createHeader(title, description, link, lastBuildDate, managingEditor) {
return `<title>${title}</title>
<description>${description}</description>
<link>${link}</link>
<lastBuildDate>${lastBuildDate}</lastBuildDate>
<managingEditor>${managingEditor}</managingEditor>`
}
function createItem(title, link, guid, pubDate, description) {
return `<item>
<title>${title}</title>
<link>${link}</link>
<guid isPermaLink="false">${guid}</guid>
<pubDate>${pubDate}</pubDate>
<description>${description}</description>
</item>`
}
function createRss(header, items) {
return `<rss version="2.0">
<channel>
${header}
${items.map(item => item).join('\n ')}
</channel>
</rss>`
}
const header = createHeader("Uptime Bot", "Uptime Bot", "https://uptimebot.com", new Date().toUTCString(), "contact@uptimebot.com UptimeBot Team")
const items = [
createItem("Downtime on Service 1", "https://uptimebot.com/events/1", "urn:uuid:99d27943-7052-4095-a3dd-533bc44336b8", new Date().toUTCString(), "Service 1 is down"),
createItem("Downtime on Service 2", "https://uptimebot.com/events/2", "urn:uuid:fc666884-35f8-4b26-9c24-f6cb78a2d581", new Date().toUTCString(), "Service 2 is down")
]
const rss = createRss(header, items)
console.log(rss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment