Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

changelog.js 1.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  1. const Parser = require('rss-parser')
  2. async function getRssFeed (url) {
  3. const parser = new Parser({ timeout: 5000 })
  4. const feedUrl = `${url}/feed`
  5. let feed
  6. try {
  7. feed = await parser.parseURL(feedUrl)
  8. } catch (err) {
  9. console.error(`cannot get ${feedUrl}: ${err.message}`)
  10. return
  11. }
  12. return feed
  13. }
  14. async function getChangelogItems (prefix, feed) {
  15. if (!feed || !feed.items) {
  16. console.log(feed)
  17. console.error('feed is not valid or has no items')
  18. return
  19. }
  20. // only show the first 3 posts
  21. const changelog = feed.items
  22. .slice(0, 3)
  23. .map(item => {
  24. // remove the prefix if it exists (Ex: 'GitHub Actions: '), where the colon and expected whitespace should be hardcoded.
  25. const title = prefix ? item.title.replace(new RegExp(`^${prefix}`), '') : item.title
  26. return {
  27. // capitalize the first letter of the title
  28. title: title.trim().charAt(0).toUpperCase() + title.slice(1),
  29. date: item.isoDate,
  30. href: item.guid
  31. }
  32. })
  33. return changelog
  34. }
  35. module.exports = { getRssFeed, getChangelogItems }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...