Skip to content

Instantly share code, notes, and snippets.

@pdxmph
Last active May 17, 2022 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdxmph/09cb94196b8ff99a7d943aed30288d4c to your computer and use it in GitHub Desktop.
Save pdxmph/09cb94196b8ff99a7d943aed30288d4c to your computer and use it in GitHub Desktop.
Populate Jekyll data directories with the jpegs found in _galleries/foo.
#!/usr/bin/env ruby
require 'yaml'
require 'mini_exiftool'
# Run this in the root of your jekyll install.
gallery_name = ARGV[0]
target_dir = "_galleries/#{gallery_name}"
data_file = "_data/galleries/#{gallery_name}.yml"
def stringify(hash)
hash.map{|k, v| [k.to_s, v.is_a?(Hash) ? stringify(v) : v] }.to_h
end
if(File.exist?(data_file))
photo_data = YAML.load_file(data_file)
else
photo_data = Hash.new
end
jpegs = Dir.glob("#{target_dir}/*.jpg")
jpegs.each do |jpeg|
jpeg_name = File.basename(jpeg)
data = MiniExiftool.new jpeg
puts data.title
if photo_data[jpeg_name] && photo_data[jpeg_name]["description"] == ''
photo_data[jpeg_name]["description"] = data.title
else
photo_data[jpeg_name] = {"description": data.title}
end
end
data_yaml = stringify(photo_data).to_yaml
File.open(data_file, "w") { |file| file.write(data_yaml) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment