generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
make-icon-list.mjs
62 lines (53 loc) · 1.21 KB
/
make-icon-list.mjs
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
import fs from 'fs';
function readFiles(dirname, onFileContent, onError, done) {
fs.readdir(dirname, function (err, filenames) {
if (err) {
onError(err);
return;
}
for (let filename of filenames) {
if (!filename.endsWith('.json')) continue;
const content = fs.readFileSync(dirname + filename);
onFileContent(filename, JSON.parse(content.toString()));
}
done();
});
}
const iconList = [];
readFiles(
'../lucide/icons/',
function (filename, content) {
const id = filename.split('.')[0];
const tags = content.tags || [];
const aliases = content.aliases || [];
iconList.push({
id: 'lucide-' + id,
aliases: [...tags, ...aliases],
});
},
function (err) {
throw err;
},
function () {
fs.writeFileSync(
'./src/iconList.ts',
`import Fuse from 'fuse.js';
import { getIconIds } from 'obsidian';
export const iconListRaw = ${JSON.stringify(iconList, null, 2)};
getIconIds().forEach(id => {
if (!/^lucide/.test(id)) {
iconListRaw.push({
id,
aliases: [],
})
}
})
export const iconList = new Fuse(iconListRaw, {
threshold: 0.1,
minMatchCharLength: 2,
keys: ['id', 'aliases'],
});
`
);
}
);