The great refactor (#82)
This commit is contained in:
40
source/plugins/pagespeed/README.md
Normal file
40
source/plugins/pagespeed/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
### ⏱️ Website performances
|
||||
|
||||
The *pagespeed* plugin adds the performance statistics of the website attached on your account:
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.pagespeed.svg">
|
||||
<details><summary>Detailed version</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.pagespeed.detailed.svg">
|
||||
</details>
|
||||
<details><summary>With screenshot version</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.pagespeed.screenshot.svg">
|
||||
</details>
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
These metrics are computed through [Google's PageSpeed API](https://developers.google.com/speed/docs/insights/v5/get-started), which yields the same results as [web.dev](https://web.dev).
|
||||
|
||||
See [performance scoring](https://web.dev/performance-scoring/) and [score calculator](https://googlechrome.github.io/lighthouse/scorecalc/) for more informations about how PageSpeed compute these statistics.
|
||||
|
||||
Although not mandatory, you can generate an API key for PageSpeed API [here](https://developers.google.com/speed/docs/insights/v5/get-started) to avoid hitting rate limiter.
|
||||
|
||||
Expect 10 to 30 seconds to generate the results.
|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_pagespeed: yes
|
||||
plugin_pagespeed_token: ${{ secrets.PAGESPEED_TOKEN }} # Optional but recommended
|
||||
plugin_pagespeed_detailed: yes # Print detailed audit metrics
|
||||
plugin_pagespeed_screenshot: no # Display a screenshot of your website
|
||||
plugin_pagespeed_url: .user.website # Website to audit (defaults to your GitHub linked website)
|
||||
```
|
||||
@@ -1,18 +1,18 @@
|
||||
//Setup
|
||||
export default async function ({login, imports, data, q}, {enabled = false, token = null} = {}) {
|
||||
export default async function ({login, imports, data, q, account}, {enabled = false, token = null} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.pagespeed)||((!data.user.websiteUrl)&&(!q["pagespeed.url"])))
|
||||
return null
|
||||
//Parameters override
|
||||
let {"pagespeed.detailed":detailed = false, "pagespeed.screenshot":screenshot = false, "pagespeed.url":url = data.user.websiteUrl} = q
|
||||
//Duration in days
|
||||
detailed = !!detailed
|
||||
|
||||
//Load inputs
|
||||
let {detailed, screenshot, url} = imports.metadata.plugins.pagespeed.inputs({data, account, q})
|
||||
//Format url if needed
|
||||
if (!/^https?:[/][/]/.test(url))
|
||||
url = `https://${url}`
|
||||
const result = {url, detailed, scores:[], metrics:{}}
|
||||
|
||||
//Load scores from API
|
||||
console.debug(`metrics/compute/${login}/plugins > pagespeed > querying api for ${url}`)
|
||||
const scores = new Map()
|
||||
@@ -31,6 +31,7 @@
|
||||
}
|
||||
}))
|
||||
result.scores = [scores.get("performance"), scores.get("accessibility"), scores.get("best-practices"), scores.get("seo")]
|
||||
|
||||
//Detailed metrics
|
||||
if (detailed) {
|
||||
console.debug(`metrics/compute/${login}/plugins > pagespeed > performing detailed audit`)
|
||||
@@ -39,6 +40,7 @@
|
||||
Object.assign(result.metrics, ...request.data.lighthouseResult.audits.metrics.details.items)
|
||||
console.debug(`metrics/compute/${login}/plugins > pagespeed > performed detailed audit (status code ${request.status})`)
|
||||
}
|
||||
|
||||
//Results
|
||||
return result
|
||||
}
|
||||
|
||||
42
source/plugins/pagespeed/metadata.yml
Normal file
42
source/plugins/pagespeed/metadata.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
name: "⏱️ Website performances"
|
||||
cost: N/A
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
- repository
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_pagespeed:
|
||||
description: Display a website Google PageSpeed metrics
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Website to audit with PageSpeed
|
||||
plugin_pagespeed_url:
|
||||
description: Audited website
|
||||
type: string
|
||||
default: .user.website
|
||||
|
||||
# Display the following additional metrics from audited website:
|
||||
# First Contentful Paint, Speed Index, Largest Contentful Paint, Time to Interactive, Total Blocking Time, Cumulative Layout Shift
|
||||
# See https://web.dev/performance-scoring/ and https://googlechrome.github.io/lighthouse/scorecalc/ for more informations
|
||||
plugin_pagespeed_detailed:
|
||||
description: Detailed audit result
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Display a screenshot of audited website
|
||||
# May increases significantly filesize
|
||||
plugin_pagespeed_screenshot:
|
||||
description: Display a screenshot of your website
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# PageSpeed API token
|
||||
# This is optional, but providing it will avoid hitting rate-limiter
|
||||
# See https://developers.google.com/speed/docs/insights/v5/get-started for more informations
|
||||
plugin_pagespeed_token:
|
||||
description: PageSpeed token
|
||||
type: token
|
||||
default: ""
|
||||
Reference in New Issue
Block a user