chore(plugins/community): move to community
This commit is contained in:
102
source/plugins/community/screenshot/README.md
Normal file
102
source/plugins/community/screenshot/README.md
Normal file
@@ -0,0 +1,102 @@
|
||||
<!--header-->
|
||||
<table>
|
||||
<tr><th colspan="2"><h3>📸 Website screenshot</h3></th></tr>
|
||||
<tr><td colspan="2" align="center"><p>This plugin display a screenshot from any website.
|
||||
It can either the full page or a portion restricted by a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors">CSS selector</a>.</p>
|
||||
</td></tr>
|
||||
<tr><th>Authors</th><td><a href="https://github.com/lowlighter">@lowlighter</a></td></tr>
|
||||
<tr>
|
||||
<th rowspan="3">Supported features<br><sub><a href="metadata.yml">→ Full specification</a></sub></th>
|
||||
<td><a href="/source/templates/classic"><code>📗 Classic template</code></a> <a href="/source/templates/repository"><code>📘 Repository template</code></a> <a href="/source/templates/terminal"><code>📙 Terminal template</code></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>👤 Users</code> <code>👥 Organizations</code> <code>📓 Repositories</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i>No tokens are required for this plugin</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="center">
|
||||
<img src="https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.screenshot.svg" alt=""></img>
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--/header-->
|
||||
|
||||
## ➡️ Available options
|
||||
|
||||
<!--options-->
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center" nowrap="nowrap">Type</i></td><td align="center" nowrap="nowrap">Description</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_screenshot</code></td>
|
||||
<td rowspan="2"><p>Enable screenshot plugin</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>boolean</code>
|
||||
<br>
|
||||
<b>default:</b> no<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_screenshot_title</code></td>
|
||||
<td rowspan="2"><p>Title caption</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>string</code>
|
||||
<br>
|
||||
<b>default:</b> Screenshot<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_screenshot_url</code></td>
|
||||
<td rowspan="2"><p>Website url</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>string</code>
|
||||
<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_screenshot_selector</code></td>
|
||||
<td rowspan="2"><p>CSS Selector</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>string</code>
|
||||
<br>
|
||||
<b>default:</b> body<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_screenshot_background</code></td>
|
||||
<td rowspan="2"><p>Display background</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>boolean</code>
|
||||
<br>
|
||||
<b>default:</b> yes<br></td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--/options-->
|
||||
|
||||
## ℹ️ Examples workflows
|
||||
|
||||
<!--examples-->
|
||||
```yaml
|
||||
name: XKCD of the day
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
filename: metrics.plugin.screenshot.svg
|
||||
token: ${{ secrets.METRICS_TOKEN }}
|
||||
base: ""
|
||||
plugin_screenshot: yes
|
||||
plugin_screenshot_title: XKCD of the day
|
||||
plugin_screenshot_url: https://xkcd.com
|
||||
plugin_screenshot_selector: "#comic img"
|
||||
|
||||
```
|
||||
<!--/examples-->
|
||||
14
source/plugins/community/screenshot/examples.yml
Normal file
14
source/plugins/community/screenshot/examples.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
- name: XKCD of the day
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
filename: metrics.plugin.screenshot.svg
|
||||
token: ${{ secrets.METRICS_TOKEN }}
|
||||
base: ""
|
||||
plugin_screenshot: yes
|
||||
plugin_screenshot_title: XKCD of the day
|
||||
plugin_screenshot_url: https://xkcd.com
|
||||
plugin_screenshot_selector: "#comic img"
|
||||
test:
|
||||
timeout: 1800000
|
||||
modes:
|
||||
- action
|
||||
43
source/plugins/community/screenshot/index.mjs
Normal file
43
source/plugins/community/screenshot/index.mjs
Normal file
@@ -0,0 +1,43 @@
|
||||
//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.screenshot))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {url, selector, title, background} = imports.metadata.plugins.screenshot.inputs({data, account, q})
|
||||
if (!url)
|
||||
throw {error:{message:"An url is required"}}
|
||||
|
||||
//Start puppeteer and navigate to page
|
||||
console.debug(`metrics/compute/${login}/plugins > screenshot > starting browser`)
|
||||
const browser = await imports.puppeteer.launch()
|
||||
console.debug(`metrics/compute/${login}/plugins > screenshot > started ${await browser.version()}`)
|
||||
const page = await browser.newPage()
|
||||
await page.setViewport({width:1280, height:1280})
|
||||
console.debug(`metrics/compute/${login}/plugins > screenshot > loading ${url}`)
|
||||
await page.goto(url)
|
||||
|
||||
//Screenshot
|
||||
await page.waitForSelector(selector)
|
||||
const clip = await page.evaluate(selector => {
|
||||
const {x, y, width, height} = document.querySelector(selector).getBoundingClientRect()
|
||||
return {x, y, width, height}
|
||||
}, selector)
|
||||
console.debug(`metrics/compute/${login}/plugins > screenshot > coordinates ${JSON.stringify(clip)}`)
|
||||
const [buffer] = await imports.record({page, ...clip, frames:1, background})
|
||||
const screenshot = await (await imports.jimp.read(Buffer.from(buffer.split(",").pop(), "base64"))).resize(Math.min(454 * (1 + data.large), clip.width), imports.jimp.AUTO)
|
||||
await browser.close()
|
||||
|
||||
//Results
|
||||
return {image:await screenshot.getBase64Async("image/png"), title, height:screenshot.bitmap.height, width:screenshot.bitmap.width, url}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {title:"Screenshot error", error:{message:"An error occured", instance:error}}
|
||||
}
|
||||
}
|
||||
41
source/plugins/community/screenshot/metadata.yml
Normal file
41
source/plugins/community/screenshot/metadata.yml
Normal file
@@ -0,0 +1,41 @@
|
||||
name: "📸 Website screenshot"
|
||||
category: community
|
||||
description: |
|
||||
This plugin display a screenshot from any website.
|
||||
It can either the full page or a portion restricted by a [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors).
|
||||
examples:
|
||||
default: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.screenshot.svg
|
||||
authors:
|
||||
- lowlighter
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
- repository
|
||||
scopes: []
|
||||
inputs:
|
||||
|
||||
plugin_screenshot:
|
||||
description: Enable screenshot plugin
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
plugin_screenshot_title:
|
||||
description: Title caption
|
||||
type: string
|
||||
default: Screenshot
|
||||
|
||||
plugin_screenshot_url:
|
||||
description: Website url
|
||||
type: string
|
||||
default: ""
|
||||
example: https://metrics.lecoq.io
|
||||
|
||||
plugin_screenshot_selector:
|
||||
description: CSS Selector
|
||||
type: string
|
||||
default: body
|
||||
|
||||
plugin_screenshot_background:
|
||||
description: Display background
|
||||
type: boolean
|
||||
default: yes
|
||||
Reference in New Issue
Block a user