Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ _data/results/*
_data/results-last-runs.json
package-lock.json
.env
.cache
.cache
# Local Netlify folder
.netlify
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Speedlify will also save your data to `/results.zip` so that you can download la

[![Netlify Status](https://api.netlify.com/api/v1/badges/7298a132-e366-460a-a4da-1ea352a4e790/deploy-status)](https://app.netlify.com/sites/speedlify/deploys)

## Show off scores in README's

![Custom badge](https://img.shields.io/endpoint?url=https%3A%2F%2F5feffb7d42d898fad979e6ef--cocky-engelbart-56fc92.netlify.app%2Fapi%2Fb2d9d426-shield.json)

## Known Limitations

* If you change a URL to remove a redirect (to remove or add a `www.`, moved domains, etc), you probably want to delete the old URL’s data otherwise you’ll have two entries in the results list.
Expand Down
58 changes: 58 additions & 0 deletions api.shild.11ty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const getObjectKey = require("./utils/getObjectKey.js");

class ApiEntry {
async data() {
return {
layout: false,
pagination: {
size: 1,
data: "urlsForApi",
alias: "site"
},
permalink: function(data) {
return `/api/${data.site.hash}-shield.json`;
}
};
}
render(data) {
let resultSet = data.results[data.site.hash];
if(!resultSet) {
// TODO better error message here, returns `false` string
return {
"schemaVersion": 1,
"label": "SPEEDLIFY",
"message": "NO RESULTS FOUND",
"color": "red"
};
}

let newestKey = getObjectKey(resultSet, ":newest");
if(!newestKey) {
// TODO better error message here, returns `false` string
return {
"schemaVersion": 1,
"label": "SPEEDLIFY",
"message": "NEWEST KEY NOT FOUND",
"color": "red"
};
}

let secondNewestKey = getObjectKey(resultSet, ":secondnewest");
if(resultSet[secondNewestKey]) {
resultSet[newestKey].previousRanks = resultSet[secondNewestKey].ranks;
}
let performance = resultSet[newestKey].lighthouse.performance*100;
let accessibility = resultSet[newestKey].lighthouse.accessibility*100;
let bestPractices = resultSet[newestKey].lighthouse.bestPractices*100;
let seo = resultSet[newestKey].lighthouse.seo*100;
// TODO set color based on results
return JSON.stringify({
"schemaVersion": 1,
"label": "SPEEDLIFY",
"message": `${performance}-${accessibility}-${bestPractices}-${seo}`,
"color": "green"
}, null, 2)
}
}

module.exports = ApiEntry;
Loading