forked from captainbrosset/devtools-tips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
72 lines (62 loc) · 2.41 KB
/
.eleventy.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const fetch = require('node-fetch');
const token = process.env.AUTHOR_API_TOKEN;
async function getTipAuthors(tipPath) {
try {
const response = await fetch(`https://api.github.com/repos/captainbrosset/devtools-tips/commits?path=${tipPath}`, {
headers: {
Authorization: `token ${token}`
}
});
const data = await response.json();
const alreadySeenAuthors = new Set();
return data.map(d => {
return {
// Warning: if you ever feel like getting d.author instead, so you can link to github profiles, please remember that
// not all commits on github are linked to an actual github user, and so d.author may be null.
name: d.commit.author.name,
url: `https://github.com/captainbrosset/devtools-tips/commit/${d.sha}`
};
}).filter(d => {
if (alreadySeenAuthors.has(d.name)) {
return false;
} else {
alreadySeenAuthors.add(d.name);
return true;
}
});
} catch (e) {
console.error(`Error finding authors for ${tipPath}`, e);
return [];
}
}
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("src/assets");
eleventyConfig.addPassthroughCopy("CNAME");
eleventyConfig.addNunjucksAsyncShortcode("authors", async function(path) {
const authors = await getTipAuthors(path);
if (!authors.length) {
return '';
}
return `<ul class="authors">${authors.map(data => `<li><a href="${data.url}">${data.name}</a></li>`).join('')}</ul>`;
});
eleventyConfig.addFilter("processBrowserTagName", function (name) {
return name.split(':')[1];
});
eleventyConfig.addFilter("onlyTags", function (tags) {
return tags.filter(tag => !tag.startsWith('browser:'));
});
eleventyConfig.addFilter("onlyBrowsers", function (browsers) {
return browsers.filter(browser => browser.startsWith('browser:'));
});
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
eleventyConfig.addPlugin(syntaxHighlight);
return {
dir: {
input: "src",
output: "dist",
data: "data",
layouts: "layouts"
}
}
};