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:
parent
f8883c1fe8
commit
c9a57027a6
@ -152,7 +152,7 @@ async function serveStaticSite(port = 3000) {
|
|||||||
console.log(`Parameters: quality=${quality}, width=${width}`);
|
console.log(`Parameters: quality=${quality}, width=${width}`);
|
||||||
|
|
||||||
// If quality parameter is present, serve a resized version
|
// 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 {
|
try {
|
||||||
const Sharp = (await import('sharp')).default;
|
const Sharp = (await import('sharp')).default;
|
||||||
|
|
||||||
@ -175,7 +175,8 @@ async function serveStaticSite(port = 3000) {
|
|||||||
})
|
})
|
||||||
.jpeg({
|
.jpeg({
|
||||||
quality: parseInt(quality),
|
quality: parseInt(quality),
|
||||||
progressive: true
|
progressive: true,
|
||||||
|
force: true // Force JPEG output regardless of input format
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get processed image info
|
// Get processed image info
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user