mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-07 12:57:49 +00:00
chore: optimize assets
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user