diff options
-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 |