feat: add auto index.json generation

This commit is contained in:
Kentai Radiquum 2025-01-15 21:45:01 +05:00
parent 23c206fbe6
commit cdbda95bff
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
3 changed files with 37 additions and 31 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
node_modules node_modules
stickerpacks/**/*.json stickerpacks/**/*.json
*.html
ignore/ ignore/

View file

@ -1,6 +1,7 @@
const config = { const config = {
stickerPacksDir: "./stickerpacks", stickerPacksDir: "./stickerpacks",
outDir: "./", outDir: "./",
homeserverUrl: "https://synapse.wah.su/__thumbnail/"
} }
module.exports = config module.exports = config

View file

@ -4,16 +4,25 @@ const fs = require("fs");
const _CreatePackPage = require("./templates/pack"); const _CreatePackPage = require("./templates/pack");
const _CreatePacksIndex = require("./templates/index"); const _CreatePacksIndex = require("./templates/index");
function GenerateStaticSite() {
let PackIndex = null let PackIndex = null
let Packs = []; let Packs = [];
try { const dirents = fs.readdirSync(config.stickerPacksDir, { withFileTypes: true });
PackIndex = JSON.parse(fs.readFileSync(config.stickerPacksDir + "/index.json")); const files = dirents
} catch (e) { .filter(dirent => dirent.isFile())
console.error("No index.json found!"); .filter(dirent => dirent.name.endsWith(".json"))
.map(dirent => dirent.name);
if (files.length == 0) {
console.error("[ERROR] NO Sticker Packs Found!");
process.exit(1); process.exit(1);
} }
console.log("[INFO] Found " + files.length + " sticker packs");
PackIndex = {
homeserver_url: config.homeserverUrl,
packs: files
}
fs.writeFileSync(config.stickerPacksDir + "/index.json", JSON.stringify(PackIndex));
if (!fs.existsSync(config.outDir)) fs.mkdirSync(config.outDir); if (!fs.existsSync(config.outDir)) fs.mkdirSync(config.outDir);
@ -33,8 +42,3 @@ function GenerateStaticSite() {
}) })
fs.writeFileSync(config.outDir + "/index.html", _CreatePacksIndex(PackIndex, Packs)); fs.writeFileSync(config.outDir + "/index.html", _CreatePacksIndex(PackIndex, Packs));
console.log("Generation complete"); console.log("Generation complete");
}
GenerateStaticSite();
module.exports = GenerateStaticSite