Refactor image processing logic in generateSite.js to use a case-insensitive regex for file type checks and added a 'force' option for JPEG output. This improves flexibility in handling image formats and ensures consistent output quality.

This commit is contained in:
Knight 2024-12-28 11:40:25 -05:00
parent f8883c1fe8
commit c9a57027a6

View File

@ -152,7 +152,7 @@ async function serveStaticSite(port = 3000) {
console.log(`Parameters: quality=${quality}, width=${width}`);
// If quality parameter is present, serve a resized version
if (quality && width && (filePath.endsWith('.jpg') || filePath.endsWith('.jpeg') || filePath.endsWith('.png'))) {
if (quality && width && /\.(jpe?g|png)$/i.test(filePath)) { // Case-insensitive check
try {
const Sharp = (await import('sharp')).default;
@ -175,7 +175,8 @@ async function serveStaticSite(port = 3000) {
})
.jpeg({
quality: parseInt(quality),
progressive: true
progressive: true,
force: true // Force JPEG output regardless of input format
});
// Get processed image info