forked from 11ty/11ty-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-avatars-twitter.js
95 lines (82 loc) · 2.34 KB
/
node-avatars-twitter.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const slugify = require("slugify");
const fs = require("fs-extra");
const fastglob = require("fast-glob");
const eleventyImg = require("@11ty/eleventy-img");
const cleanName = require("./config/cleanAuthorName");
eleventyImg.concurrency = 5;
async function fetch(name) {
if(!name) {
return;
}
let slug = slugify(name).toLowerCase();
let dir = `./avatars/twitter/`;
await fs.ensureDir(dir);
let path = `${dir}${slug}.json`;
try {
let stats = await eleventyImg(`https://unavatar.now.sh/twitter/${name}?fallback=false`, { // ?fallback=false
formats: ["webp", "jpeg"],
widths: [90],
urlPath: "/img/avatars/twitter/",
outputDir: "img/avatars/twitter/",
cacheOptions: {
duration: "14d",
}
});
return fs.writeFile(path, JSON.stringify(stats, null, 2));
} catch(e) {
console.log( "Error: ", e );
// return fs.unlink(path);
}
}
(async function() {
let twitterUsernames = new Set();
// Twitter
let testimonials = require("./_data/testimonials.json").map(entry => entry.twitter);
for(let twitter of testimonials) {
twitterUsernames.add(cleanName(twitter).toLowerCase());
}
// Starters
let starters = await fastglob("./_data/starters/*.json", {
caseSensitiveMatch: false
});
for(let site of starters) {
let siteData = require(site);
if(siteData.author) {
twitterUsernames.add(cleanName(siteData.author).toLowerCase());
}
}
// Plugins
let plugins = await fastglob("./_data/plugins/*.json", {
caseSensitiveMatch: false
});
for(let plugin of plugins) {
let pluginData = require(plugin);
if(pluginData.author) {
twitterUsernames.add(cleanName(pluginData.author).toLowerCase());
}
}
// Extras
let extras = require("./_data/extraAvatars.json").map(entry => entry.twitter);
for(let twitter of extras) {
twitterUsernames.add(cleanName(twitter).toLowerCase());
}
let sites = await fastglob("./_data/sites/*.json", {
caseSensitiveMatch: false
});
for(let site of sites) {
let siteData = require(site);
if(siteData.twitter) {
twitterUsernames.add(cleanName(siteData.twitter).toLowerCase());
}
if(siteData.authoredBy) {
for(let author of siteData.authoredBy) {
twitterUsernames.add(cleanName(author).toLowerCase());
}
}
}
console.log( "Found", twitterUsernames.size, "usernames" );
let sorted = Array.from(twitterUsernames).sort();
for(let name of sorted) {
await fetch(name);
}
})();