The great refactor (#82)
This commit is contained in:
23
source/plugins/posts/README.md
Normal file
23
source/plugins/posts/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
### ✒️ Recent posts
|
||||
|
||||
The recent *posts* plugin displays recent articles you wrote on an external source, like [dev.to](https://dev.to).
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.posts.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_posts: yes
|
||||
plugin_posts_source: dev.to # External source
|
||||
plugin_people_user: .github.user # Use same username as GitHub login
|
||||
```
|
||||
@@ -1,14 +1,14 @@
|
||||
//Setup
|
||||
export default async function ({login, imports, q}, {enabled = false} = {}) {
|
||||
export default async function ({login, data, imports, q, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.posts))
|
||||
return null
|
||||
//Parameters override
|
||||
let {"posts.source":source = "", "posts.limit":limit = 4, "posts.user":user = login} = q
|
||||
//Limit
|
||||
limit = Math.max(1, Math.min(30, Number(limit)))
|
||||
|
||||
//Load inputs
|
||||
let {source, limit, user} = imports.metadata.plugins.posts.inputs({data, account, q})
|
||||
|
||||
//Retrieve posts
|
||||
console.debug(`metrics/compute/${login}/plugins > posts > processing with source ${source}`)
|
||||
let posts = null
|
||||
@@ -23,6 +23,7 @@
|
||||
default:
|
||||
throw {error:{message:`Unsupported source "${source}"`}}
|
||||
}
|
||||
|
||||
//Format posts
|
||||
if (Array.isArray(posts)) {
|
||||
//Limit tracklist
|
||||
@@ -33,6 +34,7 @@
|
||||
//Results
|
||||
return {source, list:posts}
|
||||
}
|
||||
|
||||
//Unhandled error
|
||||
throw {error:{message:`An error occured (could not retrieve posts)`}}
|
||||
}
|
||||
|
||||
35
source/plugins/posts/metadata.yml
Normal file
35
source/plugins/posts/metadata.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
name: "✒️ Recent posts"
|
||||
cost: N/A
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_posts:
|
||||
description: Display recent posts
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Posts external source
|
||||
plugin_posts_source:
|
||||
description: Posts external source
|
||||
type: string
|
||||
default: ""
|
||||
values:
|
||||
- dev.to # Dev.to
|
||||
|
||||
# Number of posts to display
|
||||
plugin_posts_limit:
|
||||
description: Maximum number of posts to display
|
||||
type: number
|
||||
default: 4
|
||||
min: 1
|
||||
max: 30
|
||||
|
||||
# Username on external posts source
|
||||
plugin_posts_user:
|
||||
description: Posts external source username
|
||||
type: string
|
||||
default: .user.login
|
||||
|
||||
Reference in New Issue
Block a user