-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-imagedata.js
executable file
·38 lines (27 loc) · 1.01 KB
/
generate-imagedata.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
#!/bin/node
const fs = require("fs");
const IMAGES_DIR = "./content/images/";
var list = [];
directories = fs.readdirSync(IMAGES_DIR, { withFileTypes: true });
directories.forEach(category_dir => {
if (category_dir.isDirectory()) {
directory = {};
directory["name"] = category_dir.name;
try {
let title = fs.readFileSync(IMAGES_DIR + category_dir.name + "/title.txt",
{encoding: 'utf8', flag: 'r'});
directory["title"] = title.trim();
} catch (e) {
directory["title"] = category_dir.name;
}
directory["images"] = [];
directories = fs.readdirSync(IMAGES_DIR + category_dir.name, { withFileTypes: true });
directories.forEach(image => {
if (image.isFile() && image.name != "title.txt") {
directory["images"].push(image.name);
}
});
list.push(directory);
}
});
fs.writeFileSync("content/imagedata.js", "var imagedata = " + JSON.stringify(list));