chore: optimize assets

This commit is contained in:
Torsten Dittmann
2024-08-21 15:07:51 +02:00
parent 7b45ebc92e
commit 5ccac0be9b
47 changed files with 10 additions and 7 deletions

View File

@@ -1,9 +1,10 @@
import { readdirSync, statSync } from 'fs';
import { join } from 'path';
import { join, relative } from 'path';
import sharp from 'sharp';
import { fileURLToPath } from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const root_dir = join(__dirname, '../static');
const config = {
jpeg: { quality: 80 },
@@ -33,10 +34,14 @@ function isImage(file) {
return imageExtensions.includes(extension);
}
function get_relative_path(file) {
return relative(root_dir, file)
}
async function main() {
for (const file of walkSync(join(__dirname, '../static'))) {
if (!isImage(file)) continue;
console.log(file);
console.log(get_relative_path(file));
const image = sharp(file);
const size_before = (await image.toBuffer()).length;