Add RSS plugin (#192)
This commit is contained in:
23
source/plugins/rss/README.md
Normal file
23
source/plugins/rss/README.md
Normal 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
|
||||
```
|
||||
34
source/plugins/rss/index.mjs
Normal file
34
source/plugins/rss/index.mjs
Normal 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}}
|
||||
}
|
||||
}
|
||||
30
source/plugins/rss/metadata.yml
Normal file
30
source/plugins/rss/metadata.yml
Normal 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
|
||||
6
source/plugins/rss/tests.yml
Normal file
6
source/plugins/rss/tests.yml
Normal 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
|
||||
Reference in New Issue
Block a user