diff options
author | Julian T <julian@jtle.dk> | 2020-06-04 00:31:00 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-06-04 00:31:00 +0200 |
commit | b68e2ded3bca661c0364deb9ce6097d650f5bef5 (patch) | |
tree | 3f5dc9722976aec3c83598b9b9ca3dc50488216d | |
parent | a0177ad890fc8459b5245d4cf9332b1b3470e9be (diff) |
Added cleaning function
-rwxr-xr-x | build.rb | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -45,13 +45,17 @@ OptionParser.new do |opts| opts.on("-s", "--size SIZE", "Size to resize images to") do |size| options[:size] = size end - opts.on("-c", "--commit HASH", "Commit to display on website") do |hash| + opts.on("-g", "--commit HASH", "Commit to display on website") do |hash| options[:commit] = hash end + opts.on("-c", "--clean", "Cleanup unused images") do |v| + options[:clean] = true + end end.parse! options[:path] = "build" unless options[:path] options[:size] = "1920x1080" unless options[:size] +options[:clean] = false unless options[:clean] puts options # Create build dir @@ -78,8 +82,6 @@ puts files template = File.read("index.tmpl") template = template.split("%BODY%") -print(template) - File.open(File.join(options[:path], "index.html"), "w") do |file| # Print preample file.write(template[0]) @@ -106,3 +108,14 @@ File.open(File.join(options[:path], "index.html"), "w") do |file| # Print postampleee? file.write(template[1]) end + +# Cleanup old files +if options[:clean] + Dir.glob(File.join(options[:path], "*.jpg")) do |file| + hash = File.basename(file) + if !files.values.include? hash + puts "Cleaning #{hash}" + File.delete(file) + end + end +end |