From b68e2ded3bca661c0364deb9ce6097d650f5bef5 Mon Sep 17 00:00:00 2001 From: Julian T Date: Thu, 4 Jun 2020 00:31:00 +0200 Subject: Added cleaning function --- build.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'build.rb') diff --git a/build.rb b/build.rb index 6d74536..9bbca1e 100755 --- a/build.rb +++ b/build.rb @@ -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 -- cgit v1.2.3