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
|
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');
const getTabBtnSelector = type => `[href="/cheatsheet/free/${type}"]`;
const types = ['solid', 'regular', 'brands'];
async function start() {
const b = await puppeteer.launch({ headless: true });
const p = await b.newPage();
console.log('Downloading...');
await p.goto('https://fontawesome.com/cheatsheet/free/solid');
const icons = {};
for (const type of types) {
await p.click(getTabBtnSelector(type));
const data = await p.evaluate((type) => {
const getClass = type => ({
solid: '.fas',
regular: '.far',
brands: '.fab',
})[type];
return [...document.querySelectorAll(`section article`)]
.map($el => ({
label: $el.id,
icon: $el.querySelector(getClass(type)).textContent,
// group: type,
}));
}, type);
icons[type] = data;
}
b.close();
console.log('Saving to icons...');
Object.entries(icons).forEach(([type, icons]) => {
const iconsContent = icons
.map(({ label, icon, group }) => `${icon}|${label}`)
.join('\n');
fs.writeFileSync(path.resolve(__dirname, `icons/${type}`), iconsContent);
});
}
start();
|