-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
42 lines (33 loc) · 972 Bytes
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true
@out_directory = '_site'
directory @out_directory
task default: [:compress]
def images
Rake::FileList.new(
File.join(@out_directory, 'images', '*.png'),
File.join(@out_directory, 'images', '*.jpeg'),
File.join(@out_directory, 'images', '*.jpg')
)
end
task compress: [:images]
multitask webp: images.pathmap('%p.webp')
task images: [:exif, :crush, :webp]
rule '.png.webp' => ['.png'] do |t|
sh "cwebp -z 9 -lossless \"#{t.source}\" -o \"#{t.name}\""
end
rule '.jpeg.webp' => '.jpeg' do |t|
sh "cwebp -q 80 \"#{t.source}\" -o \"#{t.name}\""
end
rule '.jpg.webp' => '.jpg' do |t|
sh "cwebp -q 80 \"#{t.source}\" -o \"#{t.name}\""
end
task :exif do
image_dir = File.join(@out_directory, 'images')
sh "exiftool -overwrite_original -r -all= #{image_dir}"
end
task :crush do
pngs = Rake::FileList.new(File.join(@out_directory, 'images', '*.png'))
pngs.each do |png|
sh "pngcrush -ow \"#{png}\""
end
end