Generate .webp instead of .png

This commit is contained in:
Kazuhiro MUSASHI 2021-03-06 16:57:20 +09:00
parent b2a5552339
commit 0def02e164
1 changed files with 17 additions and 5 deletions

View File

@ -1,15 +1,27 @@
#!/usr/bin/env rake #!/usr/bin/env rake
OGP_DIR = 'static/ogp/'
CONTENT_DIR = 'content/'
FONT_DIR = 'assets/font/'
CONFIG = 'assets/tcardgen.yaml'
desc 'Generate OGP images' desc 'Generate OGP images'
task :tcard do task :tcard do
sh 'find static/ogp/ -type f -name "*.png" | grep -v "base.png" | xargs -t --no-run-if-empty rm' sh "find #{OGP_DIR} -type f -name '*.png' | xargs -t --no-run-if-empty rm"
Dir.glob("**/*.md", File::FNM_DOTMATCH, base: 'content/').each do |article| Dir.glob("**/*.md", File::FNM_DOTMATCH, base: CONTENT_DIR).each do |article|
unless article =~ /_index\.md/ unless article =~ /_index\.md/
target = File.join('content', article) target = File.join(CONTENT_DIR, article)
sh "tcardgen -f ~/repo/sample-font/ -o static/ogp/ -c config/tcardgen.yaml #{target}" sh "tcardgen -f #{FONT_DIR} -o #{OGP_DIR} -c #{CONFIG} #{target}"
end end
end end
#sh 'find content/ -type f -name "*.md" | xargs -t -I % tcardgen -f ~/repo/sample-font/ -o static/ogp/ -c config/tcardgen.yaml %' Dir.glob("*.png", File::FNM_DOTMATCH, base: OGP_DIR).each do |png|
src = File.join(OGP_DIR, png)
tmp = File.basename(src, ".*") + ".webp"
dest = File.join(OGP_DIR, tmp)
sh "img2webp -lossy -q 50 #{src} -o #{dest}"
end
end end