-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (38 loc) · 1.07 KB
/
index.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
const express = require("express");
const request = require("request");
const cheerio = require("cheerio");
const app = express();
const url = "https://fontawesome.com/cheatsheet";
const PORT = process.env.PORT || 4000;
/* GET home page. */
app.get("/", function(req, res, next) {
var faIcons = {
light: [],
solid: [],
regular: [],
brands: [],
all: []
};
request(url, function(error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
$("script").each(function() {
var text = $(this).html();
if (text.includes("window.__inline_data__ =")) {
var sc = text.replace("window.__inline_data__ =", "").trim();
var json = JSON.parse(sc);
var data = json[2]["data"];
data.map(function(d) {
var styles = d.attributes.styles;
styles.map(function(s) {
faIcons[s].push(d.id);
});
faIcons["all"].push(d.id);
});
res.json(faIcons);
}
});
}
});
});
app.listen(PORT);