feat: initial version
publish-content / build (push) Canceled after 0s

This commit is contained in:
2026-09-05 20:39:54 +05:00
parent 960e098ff7
commit b1b4d29803
24 changed files with 4321 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import sharp from 'sharp';
import crypto from 'node:crypto';
import fs from 'node:fs/promises';
import path from 'node:path';
export async function hashFile(p) {
const buf = await fs.readFile(p);
return crypto.createHash('sha256').update(buf).digest('hex').slice(0, 8);
}
export async function optimizeImage(src, dest, { width = 640, height = null } = {}) {
await fs.mkdir(path.dirname(dest), { recursive: true });
let img = sharp(src);
img = height
? img.resize(width, height, { fit: 'cover' })
: img.resize({ width, withoutEnlargement: true });
await img.webp({ quality: 80 }).toFile(dest);
}