refactor: massive USRPFP overhaul (#3)

This repo completely overhauls how USRPFP works. Some changes include:
- Deleted some leftover files
- Edited README.md a bit
- Avatars and badges are now stored in `db/data.json`
- CSS file (`db/dist.css`) is automatically generated by a GitHub
workflow

If you have questions, lmk
This commit is contained in:
nexpid 2023-08-29 12:12:01 +02:00 committed by GitHub
parent ea2d738175
commit 5a5d2c2a2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 288 additions and 377 deletions

55
.github/scripts/generate/index.mjs vendored Normal file
View file

@ -0,0 +1,55 @@
import { readFile, writeFile } from "fs/promises";
import { join } from "path";
import UglifyCSS from "uglifycss";
console.time("Done");
const uglify = !process.argv.includes("--debug");
console.log("Getting templates...");
const templateLines = (
await readFile(join("../../", "db", "template.css"), "utf8")
)
.replace(/\r/g, "")
.split("\n");
const templates = {
avatar: "",
badge: "",
};
for (const id of Object.keys(templates)) {
const start = templateLines.findIndex(
(x) => x === `/* ${id.toUpperCase()}-TEMPLATE-BEGIN */`
),
end = templateLines.findIndex(
(x) => x === `/* ${id.toUpperCase()}-TEMPLATE-END */`
);
if (start >= 0 && end >= 0)
templates[id] = templateLines.slice(start + 1, end).join("\n");
else throw new Error(`Failed to get template lines for: ${id}`);
}
console.log("Generating dist.css...");
const data = JSON.parse(
await readFile(join("../../", "db", "data.json"), "utf8")
);
const dist = [];
for (const [id, img] of Object.entries(data.avatars)) {
dist.push(templates.avatar.replace(/{id}/g, id).replace(/{img}/g, img));
}
for (const [username, img] of Object.entries(data.badges)) {
dist.push(
templates.badge.replace(/{username}/g, username).replace(/{img}/g, img)
);
}
await writeFile(
join("../../", "db", "dist.css"),
uglify ? UglifyCSS.processString(dist.join("\n")) : dist.join("\n\n")
);
console.timeEnd("Done");