summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-06-04 00:31:00 +0200
committerJulian T <julian@jtle.dk>2020-06-04 00:31:00 +0200
commitb68e2ded3bca661c0364deb9ce6097d650f5bef5 (patch)
tree3f5dc9722976aec3c83598b9b9ca3dc50488216d
parenta0177ad890fc8459b5245d4cf9332b1b3470e9be (diff)
Added cleaning function
-rwxr-xr-xbuild.rb19
1 files changed, 16 insertions, 3 deletions
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