From bc844b1c0d5bf55c7d259c2dc56564eb731663df Mon Sep 17 00:00:00 2001 From: Julian T Date: Wed, 3 Jun 2020 23:58:42 +0200 Subject: Added build script --- build.rb | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ imginfo.yml | 16 ++++++++++ index.tmpl | 16 ++++++++++ 3 files changed, 133 insertions(+) create mode 100755 build.rb create mode 100644 imginfo.yml create mode 100644 index.tmpl diff --git a/build.rb b/build.rb new file mode 100755 index 0000000..3e594b1 --- /dev/null +++ b/build.rb @@ -0,0 +1,101 @@ +#!/usr/bin/env ruby + +require 'yaml' +require 'optparse' +require 'digest' +require 'mini_magick' +require 'fileutils' +require 'erb' + +def copyimage(path, file, target) + hash = Digest::MD5.file(file).hexdigest + filename = "#{hash}.jpg" + 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.write(dest) + + return filename +end + +def forImgs(imgs, &block) + if imgs.respond_to?("each") + imgs.each &block + else + block.call(imgs) + 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 +end.parse! + +if !options[:path] + options[:path] = "build" +end + +# Create build dir +FileUtils.mkdir_p(options[:path]) + +defs = YAML.load(File.read("imginfo.yml")) +files = {} + +puts defs + +defs["groups"].each do |key, value| + + # For each image inside group + forImgs(value["imgs"]) do |img| + puts "Converting file #{img}" + dest = copyimage(options[:path], img, defs["target"]) + files[img] = dest + end + +end + +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]) + + file.puts "

Original images can be found at https://git.jtle.dk/wallpapers

" + + defs["groups"].each do |key, value| + file.puts "

#{key}

" + forImgs(value["imgs"]) do |img| + file.puts "" + end + + if value["what"] + file.puts "

#{value["what"]}" + end + + end + + + if options[:commit] + file.puts "

Build from commit #{options[:commit]}

" + end + + # Print postampleee? + file.write(template[1]) +end diff --git a/imginfo.yml b/imginfo.yml new file mode 100644 index 0000000..e8dba0b --- /dev/null +++ b/imginfo.yml @@ -0,0 +1,16 @@ +target: 1920x1080 +groups: + Flowering tree: + imgs: blomster.jpg + Flowers: + imgs: blomster2.jpg + what: Begonia rex at home + Tangeværket: + imgs: + - el.jpg + - maskiner.jpg + Dwingeloo: + imgs: Struktur.jpg + Moonpictures: + imgs: måne.jpg + diff --git a/index.tmpl b/index.tmpl new file mode 100644 index 0000000..4810c4e --- /dev/null +++ b/index.tmpl @@ -0,0 +1,16 @@ + + + + Jtle images + + + + + + %BODY% + + -- cgit v1.2.3