From e941f99229b18f50c727c48ace3049433b211940 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sun, 21 Apr 2024 22:18:45 -0500 Subject: [PATCH] Add Ruby script to generate photo post --- .tool-versions | 1 + Gemfile | 5 +++++ Gemfile.lock | 26 ++++++++++++++++++++++++++ archetypes/photos/index.md.erb | 20 ++++++++++++++++++++ bin/create_photo | 30 ++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 archetypes/photos/index.md.erb create mode 100755 bin/create_photo diff --git a/.tool-versions b/.tool-versions index 48acfd78..cd5b5582 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1,2 @@ hugo extended_0.120.4 +ruby 3.2.2 diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..8c646e8f --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "erb" +gem "exiftool" +gem "pry" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..deed72d7 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,26 @@ +GEM + remote: https://rubygems.org/ + specs: + cgi (0.4.1) + coderay (1.1.3) + erb (4.0.4) + cgi (>= 0.3.3) + exiftool (1.2.5) + json + json (2.7.2) + method_source (1.1.0) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + +PLATFORMS + arm64-darwin-23 + ruby + +DEPENDENCIES + erb + exiftool + pry + +BUNDLED WITH + 2.5.9 diff --git a/archetypes/photos/index.md.erb b/archetypes/photos/index.md.erb new file mode 100644 index 00000000..1fdf5947 --- /dev/null +++ b/archetypes/photos/index.md.erb @@ -0,0 +1,20 @@ +--- +title: "<%= photo[:title] %>" +date: <%= date %> +categories: +tags: +layout: post +image: <%= photo[:file_name] %> +--- + +
+ <%= photo[:image_description] %> + +
+ <%= photo[:model] %>, + <%= (photo[:focal_length35efl] || photo[:focal_length]).gsub(" mm", "mm") %>, + ISO <%= photo[:iso] %>, + <%= photo[:shutter_speed] %> + at ƒ/<%= photo[:f_number] %> +
+
diff --git a/bin/create_photo b/bin/create_photo new file mode 100755 index 00000000..49b69dc8 --- /dev/null +++ b/bin/create_photo @@ -0,0 +1,30 @@ +#!/usr/bin/env ruby +require "erb" +require "exiftool" +require "i18n" +require "pry" + +I18n.config.available_locales = :en + +def parameterize(string) + I18n.transliterate(string) + .downcase + .gsub(/[^a-z]+/, "-") +end + +photo_path = ARGV.first + +photo = Exiftool.new(photo_path) +date = Date.today.iso8601 + +template = ERB.new(File.read("archetypes/photos/index.md.erb")) + +post_dir = "content/photos/#{date}-#{parameterize(photo[:title])}" + +if !Dir.exist?(post_dir) + Dir.mkdir(post_dir) +end + +FileUtils.cp(photo_path, "#{post_dir}/#{photo[:file_name]}") + +File.write("#{post_dir}/index.md", template.result)