forked from zachleat/speedlify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.11ty.js
39 lines (34 loc) · 874 Bytes
/
api.11ty.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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}.json`;
}
};
}
render(data) {
let resultSet = data.results[data.site.hash];
if(!resultSet) {
// TODO better error message here, returns `false` string
return false;
}
let newestKey = getObjectKey(resultSet, ":newest");
if(!newestKey) {
// TODO better error message here, returns `false` string
return false;
}
let secondNewestKey = getObjectKey(resultSet, ":secondnewest");
if(resultSet[secondNewestKey]) {
resultSet[newestKey].previousRanks = resultSet[secondNewestKey].ranks;
}
return JSON.stringify(resultSet[newestKey], null, 2);
}
}
module.exports = ApiEntry;