-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
105 lines (93 loc) Β· 2.37 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
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
96
97
98
99
100
101
102
103
104
105
const json2md = require("json2md");
const fetch = require("node-fetch");
const fs = require("fs");
const URLS = {
GITHUB: "https://github.com",
THEMES:
"https://raw.githubusercontent.com/obsidianmd/obsidian-releases/master/community-css-themes.json",
PLUGINS:
"https://raw.githubusercontent.com/obsidianmd/obsidian-releases/master/community-plugins.json",
};
async function createTable(json, type) {
let labels = [];
let rows = [];
if (type === "plugins") {
labels = [
// "id",
"π Name",
// "author",
"β¨ Description",
// "repo"
];
}
if (type === "themes") {
labels = [
// "name",
// "author",
"π Repository",
"π· Screenshot",
// "modes"
];
}
// fix: trims line to prevent table breaking (https://github.com/IonicaBizau/json2md/issues/80), this should be fixed in some way, e.g. forking repo and fixing this bug
for (const obj of json) {
if (type === "plugins") {
rows.push([
// obj.id,
json2md({
link: { title: obj.name, source: encodeURI(`${URLS.GITHUB}/${obj.repo}`) },
}).trim(),
// obj.author,
obj.description,
// obj.repo,
]);
} else if (type === "themes") {
rows.push([
// obj.name,
// obj.author,
json2md([
{
link: {
title: obj.repo,
source: encodeURI(`${URLS.GITHUB}/${obj.repo}`),
},
},
]).trim(),
json2md([
{
img: {
alt: obj.name,
source: encodeURI(`https://raw.githubusercontent.com/${obj.repo}/master/${obj.screenshot}`),
},
},
]).trim(),
// obj.modes,
]);
}
}
const table = json2md({
table: {
headers: labels,
rows: rows,
},
});
return table;
}
async function fetchJSON(url) {
return fetch(url).then((response) => response.json());
}
async function writeTables(table, name) {
fs.writeFile(`lists/${name}.md`, table, (err) => {
if (err) {
console.error(err);
return;
}
});
}
// below to clean up
fetchJSON(URLS.THEMES)
.then((json) => createTable(json, "themes"))
.then((table) => writeTables(table, "themes"));
fetchJSON(URLS.PLUGINS)
.then((json) => createTable(json, "plugins"))
.then((table) => writeTables(table, "plugins"));