blog/tasks/tcardgen.rake

30 lines
819 B
Ruby
Raw Normal View History

2021-02-26 23:55:27 +00:00
#!/usr/bin/env rake
2021-03-06 07:57:20 +00:00
OGP_DIR = 'static/ogp/'
CONTENT_DIR = 'content/'
FONT_DIR = 'assets/font/'
CONFIG = 'assets/tcardgen.yaml'
2021-02-26 23:55:27 +00:00
desc 'Generate OGP images'
task :tcard do
2021-03-06 07:57:20 +00:00
sh "find #{OGP_DIR} -type f -name '*.png' | xargs -t --no-run-if-empty rm"
2021-03-06 07:57:20 +00:00
Dir.glob("**/*.md", File::FNM_DOTMATCH, base: CONTENT_DIR).each do |article|
unless article =~ /_index\.md/
2021-03-06 07:57:20 +00:00
target = File.join(CONTENT_DIR, article)
sh "tcardgen -f #{FONT_DIR} -o #{OGP_DIR} -c #{CONFIG} #{target}"
end
end
2021-03-06 07:57:20 +00:00
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
2021-03-06 11:34:50 +00:00
sh "find #{OGP_DIR} -type f -name '*.png' | xargs -t --no-run-if-empty rm"
2021-02-26 23:55:27 +00:00
end