summaryrefslogtreecommitdiff
path: root/build.rb
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-04-03 23:12:04 +0200
committerJulian T <julian@jtle.dk>2021-04-03 23:15:25 +0200
commit4cbc2eae6335222b74129c9eaedab39250c3b7b9 (patch)
tree109eb8b854896aa5b8e8777dbebcd08c615f578b /build.rb
parent556f61555c022946e80bd5815232867bfab77f6b (diff)
Moved to python based builder
Diffstat (limited to 'build.rb')
-rwxr-xr-xbuild.rb145
1 files changed, 0 insertions, 145 deletions
diff --git a/build.rb b/build.rb
deleted file mode 100755
index 9f4ef88..0000000
--- a/build.rb
+++ /dev/null
@@ -1,145 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'yaml'
-require 'optparse'
-require 'digest'
-require 'mini_magick'
-require 'fileutils'
-require 'erb'
-
-def copyimage(path, file, target, extension)
- hash = Digest::MD5.file(file).hexdigest
- hash = Digest::MD5.hexdigest(hash.to_s + target)
- filename = "#{hash}.#{extension}"
- dest = File.join(path, filename)
-
- if File.exist?(dest)
- puts "Skipping"
- return filename
- end
-
- puts "Writing #{dest}"
- # Resize image and write it to destination
- image = MiniMagick::Image.open(file)
- image.resize(target)
- image.format(extension)
- image.write(dest)
-
- return filename
-end
-
-def forImgs(imgs, &block)
- if imgs.respond_to?("each")
- imgs.each &block
- else
- block.call(imgs)
- end
-end
-
-def placeImage(file, src, href = nil)
- if href
- file.puts "<a href=\"#{href}\">"
- end
- file.puts "<img src=\"#{src}\">"
- if href
- file.puts "</a>"
- end
-end
-
-options = {}
-OptionParser.new do |opts|
- opts.banner = "Usage: build.rb dest"
-
- opts.on("-d", "--dest PATH", "PATH to put build files") do |path|
- options[:path] = path
- end
- opts.on("-s", "--size SIZE", "Size to resize images to") do |size|
- options[:size] = size
- end
- 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
- opts.on("-b", "--linkbase URL", "Add links to images, with URL as base") do |url|
- options[:base] = url
- end
- opts.on("-e", "--extension EXT", "Image extension to use with imagemagick") do |ext|
- options[:extension] = ext
- end
-end.parse!
-
-options[:path] = "build" unless options[:path]
-options[:size] = "1920x1080" unless options[:size]
-options[:clean] = false unless options[:clean]
-options[:extension] = "jpg" unless options[:extension]
-puts options
-
-# Create build dir
-FileUtils.mkdir_p(options[:path])
-
-defs = YAML.load(File.read("imginfo.yml"))
-files = {}
-
-puts defs
-
-defs["groups"].each do |value|
-
- # For each image inside group
- forImgs(value["imgs"]) do |img|
- puts "Converting file #{img}"
- dest = copyimage(options[:path], img, options[:size], options[:extension])
- files[img] = dest
- end
-
-end
-
-puts files
-
-template = File.read("index.tmpl")
-template = template.split("%BODY%")
-
-# Cleanup old files
-if options[:clean]
- Dir.glob(File.join(options[:path], "*")) do |file|
- hash = File.basename(file)
- if !files.values.include? hash
- puts "Cleaning #{hash}"
- File.delete(file)
- end
- end
-end
-
-File.open(File.join(options[:path], "index.html"), "w") do |file|
- # Print preample
- file.write(template[0])
-
- defs["groups"].each do |value|
- file.puts "<div class=\"group\">"
- if value[:title]
- file.puts "<h2>#{value[:title]}</h2>"
- end
- forImgs(value["imgs"]) do |img|
- href = options[:base]
- # If href is given add a filename at the end
- if href
- href = File.join(href, img)
- end
-
- placeImage(file, files[img], href)
- end
-
- if value["what"]
- file.puts "<p>#{value["what"]}"
- end
- file.puts "</div>"
- end
-
- if options[:commit]
- file.puts "<p>Bygget fra commit #{options[:commit]}</p>"
- end
-
- # Print postampleee?
- file.write(template[1])
-end