1
0
mirror of synced 2025-12-21 19:06:49 -05:00
Files
docs/lib/changelog.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

41 lines
1.0 KiB
JavaScript

import Parser from 'rss-parser'
export async function getRssFeed(url) {
const parser = new Parser({ timeout: 5000 })
const feedUrl = `${url}/feed`
let feed
try {
feed = await parser.parseURL(feedUrl)
} catch (err) {
console.error(`cannot get ${feedUrl}: ${err.message}`)
return
}
return feed
}
export async function getChangelogItems(prefix, feed) {
if (!feed || !feed.items) {
console.log(feed)
console.error('feed is not valid or has no items')
return
}
// only show the first 3 posts
const changelog = feed.items.slice(0, 3).map((item) => {
// remove the prefix if it exists (Ex: 'GitHub Actions: '), where the colon and expected whitespace should be hardcoded.
const title = prefix ? item.title.replace(new RegExp(`^${prefix}`), '') : item.title
return {
// capitalize the first letter of the title
title: title.trim().charAt(0).toUpperCase() + title.slice(1),
date: item.isoDate,
href: item.link,
}
})
return changelog
}
export default { getRssFeed, getChangelogItems }