Add RSS plugin (#192)

This commit is contained in:
Simon Lecoq
2021-03-21 12:14:05 +01:00
committed by GitHub
parent 3df4159026
commit 30fb3b4a41
14 changed files with 234 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
### 🗼 Rss feed
The *rss* plugin displays items from a specified RSS feed.
<table>
<td align="center">
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.rss.svg">
<img width="900" height="1" alt="">
</td>
</table>
#### Examples workflows
[➡️ Available options for this plugin](metadata.yml)
```yaml
- uses: lowlighter/metrics@latest
with:
# ... other options
plugin_rss: yes
plugin_rss_source: https://news.ycombinator.com/rss # RSS feed
plugin_rss_limit: 6 # Limit to 6 items
```

View File

@@ -0,0 +1,34 @@
//Setup
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.rss))
return null
//Load inputs
let {source, limit} = imports.metadata.plugins.rss.inputs({data, account, q})
if (!source)
throw {error:{message:"A RSS feed is required"}}
//Load rss feed
const {title, description, link, items} = await (new imports.rss()).parseURL(source) //eslint-disable-line new-cap
const feed = items.map(({title, isoDate:date}) => ({title, date:new Date(date)}))
//Limit feed
if (limit > 0) {
console.debug(`metrics/compute/${login}/plugins > rss > keeping only ${limit} items`)
feed.splice(limit)
}
//Results
return {source:title, description, link, feed}
}
//Handle errors
catch (error) {
if (error.error?.message)
throw error
throw {error:{message:"An error occured", instance:error}}
}
}

View File

@@ -0,0 +1,30 @@
name: "🗼 Rss feed"
cost: N/A
categorie: social
index: 6.5
supports:
- user
- organization
- repository
inputs:
# Enable or disable plugin
plugin_rss:
description: Display RSS feed
type: boolean
default: no
# RSS feed source
plugin_rss_source:
description: RSS feed source
type: string
default: ""
# Number of items to display
# Set to 0 to disable limitations
plugin_rss_limit:
description: Maximum number of items to display
type: number
default: 4
min: 0
max: 30

View File

@@ -0,0 +1,6 @@
- name: Rss plugin (default)
uses: lowlighter/metrics@latest
with:
token: NOT_NEEDED
plugin_rss: yes
plugin_source: https://example.org/rss