Skip to content

Instantly share code, notes, and snippets.

@ys

ys/Gemfile Secret

Created December 5, 2022 20:08
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 ys/7955038d5f4cff4ed23d116f7884d59b to your computer and use it in GitHub Desktop.
Save ys/7955038d5f4cff4ed23d116f7884d59b to your computer and use it in GitHub Desktop.
How did I automate the creation of details?
source "https://rubygems.org"
gem "faraday"
gem "dotenv"
gem "activesupport", require: "active_support/all"
GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
concurrent-ruby (1.1.10)
dotenv (2.8.1)
faraday (2.6.0)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.1)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
minitest (5.16.3)
ruby2_keywords (0.0.5)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
PLATFORMS
arm64-darwin-21
DEPENDENCIES
activesupport
dotenv
faraday
BUNDLED WITH
2.3.7
require "bundler"
require "json"
Bundler.require
Dotenv.load
class Generator
def initialize
@dest = "/Users/ys/src/github.com/ys/bonjour/content/details"
end
def buttondown
publish_at_date = DateTime.now.next_occurring(:friday)
buttondown = Buttondown.new
Dir.new(Dir.getwd).sort_by{|f| f.split(".")[0].to_i }.select { |f| f.end_with?(".jpg") }.each do |f|
number = f.split(".")[0]
file = f
letter = letter_template.result(binding)
buttondown.publish("détail - #{number}", letter, publish_at_date.change(hour: 9, minute: 30))
publish_at_date += 1.week
end
end
def hugo
publish_at_date = DateTime.now.next_occurring(:friday)
Dir.new(Dir.getwd).sort_by{|f| f.split(".")[0].to_i }.select { |f| f.end_with?(".jpg") }.each do |f|
publish_at = publish_at_date.beginning_of_day.iso8601
color = %w{accent sunray purpleheart forest jazzberry rose teal tuscan}.sample
number = f.split(".")[0]
index = template.result(binding)
dest_dir =File.join(@dest, number)
Dir.mkdir(dest_dir) unless File.exists?(dest_dir)
File.open(File.join(dest_dir, "index.md"), "w") { |f| f.write(index) }
`convert #{f} -resize 2000x2000 -format webp #{File.join(dest_dir, "cover.webp")}`
publish_at_date += 1.week
end
end
def template
ERB.new(File.read("index.md"))
end
def letter_template
ERB.new(File.read("letter.md"))
end
end
class Buttondown
def publish(title, body, publish_date)
puts client.post("/v1/scheduled-emails", {
subject: title,
body: body,
publish_date: publish_date.iso8601
}.to_json).body
end
def url
"https://api.buttondown.email/v1/scheduled-emails"
end
def client
@client ||= Faraday.new(
url: "https://api.buttondown.email",
headers: {
"Authorization" => "Token #{ENV['BUTTONDOWN_TOKEN']}",
'Content-Type' => 'application/json',
'Accept' => 'application/json',
}
)
end
end
Generator.new.buttondown
title slug emoji letter description date color resources
<%= number %> - Détail
<%= number %>
👀
detail
Une photo par semaine, dans ta boîte mail
<%= publish_at %>
<%= color %>
src name
cover.webp
cover
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment