style updates
This commit is contained in:
@@ -14,9 +14,13 @@ final class ThemeOptimizer
|
||||
$result = ['css' => 0, 'js' => 0, 'images' => 0];
|
||||
foreach (['css' => 'css', 'js' => 'js'] as $type => $folder) {
|
||||
$directory = $theme->path().'/'.$folder;
|
||||
if (! $this->files->isDirectory($directory)) continue;
|
||||
if (! $this->files->isDirectory($directory)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($this->files->files($directory) as $file) {
|
||||
if ($file->getExtension() !== $type || str_ends_with($file->getFilename(), '.min.'.$type)) continue;
|
||||
if ($file->getExtension() !== $type || str_ends_with($file->getFilename(), '.min.'.$type)) {
|
||||
continue;
|
||||
}
|
||||
$content = $file->getContents();
|
||||
$content = preg_replace('!/\*.*?\*/!s', '', $content) ?? $content;
|
||||
$content = preg_replace('/\s+/', ' ', $content) ?? $content;
|
||||
@@ -29,15 +33,25 @@ final class ThemeOptimizer
|
||||
if (function_exists('imagewebp')) {
|
||||
foreach (['images', 'icons'] as $folder) {
|
||||
$directory = $theme->path().'/'.$folder;
|
||||
if (! $this->files->isDirectory($directory)) continue;
|
||||
if (! $this->files->isDirectory($directory)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($this->files->files($directory) as $file) {
|
||||
$ext = strtolower($file->getExtension());
|
||||
if (! in_array($ext, ['jpg', 'jpeg', 'png'], true)) continue;
|
||||
if (! in_array($ext, ['jpg', 'jpeg', 'png'], true)) {
|
||||
continue;
|
||||
}
|
||||
$image = $ext === 'png' ? @imagecreatefrompng($file->getPathname()) : @imagecreatefromjpeg($file->getPathname());
|
||||
if ($image) { imagepalettetotruecolor($image); imagewebp($image, $file->getPath().'/'.$file->getBasename('.'.$ext).'.webp', 82); imagedestroy($image); $result['images']++; }
|
||||
if ($image) {
|
||||
imagepalettetotruecolor($image);
|
||||
imagewebp($image, $file->getPath().'/'.$file->getBasename('.'.$ext).'.webp', 82);
|
||||
imagedestroy($image);
|
||||
$result['images']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user