-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.11ty.js
46 lines (43 loc) · 947 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
40
41
42
43
44
45
46
const shortHash = require("short-hash");
const getObjectKey = require("./utils/getObjectKey.js");
class Api {
data() {
return {
layout: false,
pagination: {
size: 1,
data: "sites",
before: function(paginationData) {
let data = [];
for(let vertical of paginationData) {
let verticalData = require(`./_data/sites/${vertical}.js`);
for(let url of verticalData.urls) {
data.push({
vertical: vertical,
url: url,
hash: shortHash(url),
});
}
}
return data;
},
alias: "site"
},
permalink: function(data) {
return `/api/${data.site.hash}.json`;
}
};
}
render(data) {
let resultSet = data.results[data.site.hash];
if(!resultSet) {
return false;
}
let newestKey = getObjectKey(resultSet, ":newest");
if(!newestKey) {
return false;
}
return JSON.stringify(resultSet[newestKey], null, 2);
}
}
module.exports = Api;