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 %> |
|
-
-
Save ys/7955038d5f4cff4ed23d116f7884d59b to your computer and use it in GitHub Desktop.
How did I automate the creation of details?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "faraday" | |
gem "dotenv" | |
gem "activesupport", require: "active_support/all" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
[ ![](https://bonjour-yannick.s3.fr-par.scw.cloud/details/<%= file %>) ](https://yannickschutz.com/details/<%= number %>?zoom)
[Zoom](https://yannickschutz.com/details/<%= number %>?zoom)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment