convert all images to webp

This commit is contained in:
polv committed 2026-06-25 16:34:27 +07:00
1 parent 3e3d2dcbcb
commit 3df6d87ab5
30 files changed
+9721 -9615

No files matched your search

+9 -7
View File
@@ -6,7 +6,9 @@ import matter from "gray-matter";
import { renderFile } from "./group-similar.js";
const ROOT_DIR = "docs";
const MD_ROOT_DIR = "docs";
const IMG_ROOT_DIR = "docs/public/images";
const PORT = 8080;
const wss = new WebSocketServer({ port: PORT });
@@ -19,7 +21,7 @@ wss.on("connection", (ws) => {
ws.on("message", (message, isBinary) => {
if (message instanceof Buffer && isBinary) {
writeFileSync(joinPath(ROOT_DIR, filename), message);
writeFileSync(joinPath(IMG_ROOT_DIR, filename), message);
return;
}
@@ -36,7 +38,7 @@ wss.on("connection", (ws) => {
const q_stem = make_q_stem(q);
try {
mkdirSync(joinPath(ROOT_DIR, q_stem));
mkdirSync(joinPath(IMG_ROOT_DIR, q_stem));
} catch (e) {}
let isChanged = false;
@@ -64,7 +66,7 @@ wss.on("connection", (ws) => {
const { min, sec } = m.groups;
const t = `${min}_${sec}`;
ts.push(t);
newContent += `![${line}](./${q_stem}/${t}.png)\n`;
newContent += `![${line}](/${q_stem}/${t}.webp)\n`;
newContent += `${line}\n`;
newContent += `\n`;
isChanged = true;
@@ -84,7 +86,7 @@ wss.on("connection", (ws) => {
{
const { q, t } = payload;
const q_stem = make_q_stem(q);
filename = t ? joinPath(q_stem, `${t}.png`) : "";
filename = t ? joinPath(q_stem, `${t}.webp`) : "";
}
break;
case "done":
@@ -128,10 +130,10 @@ function loadMdFile(q) {
const q_stem = make_q_stem(q);
try {
mkdirSync(joinPath(ROOT_DIR, q_stem));
mkdirSync(joinPath(MD_ROOT_DIR, q_stem));
} catch (e) {}
const filename = joinPath(ROOT_DIR, `${q_stem}.md`);
const filename = joinPath(MD_ROOT_DIR, `${q_stem}.md`);
try {
// create a blank md file if not exists
readFileSync(filename, { flag: "a" });