mirror of
https://github.com/danbee/danbarber.me.hugo.git
synced 2025-03-04 08:59:18 +00:00
Add Ruby script to generate photo post
This commit is contained in:
parent
67281a6be0
commit
e941f99229
@ -1 +1,2 @@
|
||||
hugo extended_0.120.4
|
||||
ruby 3.2.2
|
||||
|
||||
5
Gemfile
Normal file
5
Gemfile
Normal file
@ -0,0 +1,5 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "erb"
|
||||
gem "exiftool"
|
||||
gem "pry"
|
||||
26
Gemfile.lock
Normal file
26
Gemfile.lock
Normal file
@ -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
|
||||
20
archetypes/photos/index.md.erb
Normal file
20
archetypes/photos/index.md.erb
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
title: "<%= photo[:title] %>"
|
||||
date: <%= date %>
|
||||
categories:
|
||||
tags:
|
||||
layout: post
|
||||
image: <%= photo[:file_name] %>
|
||||
---
|
||||
|
||||
<figure class="photo photo--wide">
|
||||
<img src="<%= photo[:file_name] %>" alt="<%= photo[:image_description] %>">
|
||||
|
||||
<figcaption>
|
||||
<%= photo[:model] %>,
|
||||
<%= (photo[:focal_length35efl] || photo[:focal_length]).gsub(" mm", "mm") %>,
|
||||
ISO <%= photo[:iso] %>,
|
||||
<%= photo[:shutter_speed] %>
|
||||
at ƒ/<%= photo[:f_number] %>
|
||||
</figcaption>
|
||||
</figure>
|
||||
30
bin/create_photo
Executable file
30
bin/create_photo
Executable file
@ -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)
|
||||
Loading…
Reference in New Issue
Block a user