mirror of
https://github.com/danbee/danbarber.me.hugo.git
synced 2025-03-04 08:59:18 +00:00
31 lines
624 B
Ruby
Executable File
31 lines
624 B
Ruby
Executable File
#!/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] || photo[:file_name])}"
|
|
|
|
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)
|