diff options
author | Julian T <julian@jtle.dk> | 2020-06-03 23:58:42 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-06-03 23:58:42 +0200 |
commit | bc844b1c0d5bf55c7d259c2dc56564eb731663df (patch) | |
tree | f9649f4ba9d11956b489e9f12fac915bb38bc0aa | |
parent | cce5ac97fbbd54b16f523441566d9955e58e6697 (diff) |
Added build script
-rwxr-xr-x | build.rb | 101 | ||||
-rw-r--r-- | imginfo.yml | 16 | ||||
-rw-r--r-- | index.tmpl | 16 |
3 files changed, 133 insertions, 0 deletions
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 "<p>Original images can be found at https://git.jtle.dk/wallpapers</p>" + + defs["groups"].each do |key, value| + file.puts "<h2>#{key}</h2>" + forImgs(value["imgs"]) do |img| + file.puts "<img src=\"#{files[img]}\">" + end + + if value["what"] + file.puts "<p>#{value["what"]}" + end + + end + + + if options[:commit] + file.puts "<p>Build from commit #{options[:commit]}</p>" + 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 @@ +<html> + <head> + <meta charset="utf-8"> + <title>Jtle images</title> + <link rel="icon" href="/favicon.png"> + <meta name="robots" content="noindex,nofollow"> + <style> +img { + width: 90%; +} + </style> + </head> + <body> + %BODY% + </body> +</html> |