From 9bc0fe3a38f9a21be813f61de349b4da19dd3ee9 Mon Sep 17 00:00:00 2001 From: Dan Ivovich Date: Thu, 24 Oct 2024 07:57:05 -0400 Subject: [PATCH] Handle redirects and don't show transcript if it 404s --- Gemfile | 1 + Gemfile.lock | 3 +++ _data/elixir_wizards_transcripts.yml | 2 -- _scripts/podcasts.rb | 14 ++++++++++---- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 20ac4f10..f598c3fa 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,4 @@ gem 'rake' gem 'jekyll-sitemap' gem 'kramdown', '>= 2.3.1' gem 'webrick' +gem 'faraday-follow_redirects' diff --git a/Gemfile.lock b/Gemfile.lock index 7dea76bf..f9adc2b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,8 @@ GEM execjs (2.9.1) faraday (2.9.0) faraday-net_http (>= 2.0, < 3.2) + faraday-follow_redirects (0.3.0) + faraday (>= 1, < 3) faraday-net_http (3.1.0) net-http ffi (1.16.3) @@ -308,6 +310,7 @@ PLATFORMS ruby DEPENDENCIES + faraday-follow_redirects github-pages html-proofer jekyll-sitemap diff --git a/_data/elixir_wizards_transcripts.yml b/_data/elixir_wizards_transcripts.yml index 3b7ddac0..adce7eb1 100644 --- a/_data/elixir_wizards_transcripts.yml +++ b/_data/elixir_wizards_transcripts.yml @@ -287,5 +287,3 @@ elixirconf2024-hype-isode: English: "/podcast/elixir-wizards/transcripts/elixirconf2024-hype-isode.txt" s13-e01-igniter-code-generation-zach-daniel: English: "/podcast/elixir-wizards/transcripts/s13-e01-igniter-code-generation-zach-daniel.txt" -s13-e02-vintagecell-nerves-bryan-green: - English: "/podcast/elixir-wizards/transcripts/s13-e02-vintagecell-nerves-bryan-green.txt" diff --git a/_scripts/podcasts.rb b/_scripts/podcasts.rb index 55a6747b..9160baba 100644 --- a/_scripts/podcasts.rb +++ b/_scripts/podcasts.rb @@ -4,6 +4,7 @@ require 'faraday' require 'nokogiri' require 'yaml' +require 'faraday/follow_redirects' def parse_date(date) Date.parse(date).strftime("%B %e, %Y") @@ -62,15 +63,20 @@ def parse_date(date) transcript_url = transcript.attributes["url"].value unless File.exist?(transcript_path) - response = Faraday.get(transcript_url) + conn = Faraday.new(url: transcript_url) do |faraday| + faraday.response :follow_redirects # use Faraday::FollowRedirects::Middleware + end + response = conn.get(transcript_url) if response.success? File.write(transcript_path, response.body) + transcripts[slug] ||= {} + transcripts[slug]["English"] = "/#{transcript_path}" + else + puts "Couldn't get transcript for #{slug} #{transcript_url} due to #{response.status} on #{response.env.url}" + transcripts.delete(slug) end end - - transcripts[slug] ||= {} - transcripts[slug]["English"] = "/#{transcript_path}" end transcripts