Skip to content

Commit

Permalink
Add recent podcast episodes
Browse files Browse the repository at this point in the history
We fetch the most recent episodes from both the Giant Robots and Bike
Shed feeds, then list them in the README. The two feeds are combined in
order, so it appears like there's one list even though it comes from
different sources.
  • Loading branch information
nickcharlton committed Jan 2, 2025
1 parent 5d5c862 commit ea4937d
Show file tree
Hide file tree
Showing 9 changed files with 243,461 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bin/update_readme
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ require "github_readme"

readme = Readme.new("profile/README.md")
blog = RssFeed.new(url: "https://feeds.feedburner.com/GiantRobotsSmashingIntoOtherGiantRobots")
podcasts = CombinedRssFeed.new(
feed_urls: [
"https://podcast.thoughtbot.com/rss",
"https://bikeshed.thoughtbot.com/rss"
]
)

readme.update(section: "blog", items: blog.take(5))
readme.update(section: "podcasts", items: podcasts.take(5))
23 changes: 23 additions & 0 deletions lib/combined_rss_feed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "rss_feed"

class CombinedRssFeed
include Enumerable

def initialize(feed_urls:)
@rss_feeds = feed_urls.map { |url| RssFeed.new(url: url) }
end

def each
rss_feeds
.map(&:entries)
.flatten
.compact
.sort_by(&:created_at)
.reverse!
.each { |entry| yield entry }
end

private

attr_reader :rss_feeds
end
3 changes: 3 additions & 0 deletions lib/github_readme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

require "feed_item"
require "rss_feed"
require "combined_rss_feed"
require "readme"

Excon.defaults[:middlewares].push(Excon::Middleware::RedirectFollower)
2 changes: 2 additions & 0 deletions lib/rss_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require "excon"
require "feedjira"

require "feed_item"

class RssFeed
include Enumerable

Expand Down
19 changes: 19 additions & 0 deletions profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ products at every stage of the product lifecycle. Since 2003, we have produced
high-quality products for over [1,000 clients][3]. We are proud to leave every
project with a stronger team and improved processes.

<table><tr><td valign="top" width="50%">

### Podcasts

<!-- podcasts starts -->
[453: The Bike Shed Wrapped 2024](https://bikeshed.thoughtbot.com/453)

[555: AI Meets LEGO® Creativity with Keira Czarnota ](https://podcast.thoughtbot.com/555)

[452: Hotwire Essentials with Steve Polito](https://bikeshed.thoughtbot.com/452)

[554: Founding a Life Saving Business from your dorm room with Luká Yancopoulos](https://podcast.thoughtbot.com/554)

[451: Making Time for and Managing Focus](https://bikeshed.thoughtbot.com/451)

<!-- podcasts ends -->
</td><td valign="top" width="50%">

### Writing

<!-- blog starts -->
Expand All @@ -18,6 +36,7 @@ project with a stronger team and improved processes.
[The digital nomad thoughtbottle](https://thoughtbot.com/blog/the-digital-nomad-thoughtbottle)

<!-- blog ends -->
</td></tr></table>

[1]: https://thoughtbot.com
[2]: https://thoughtbot.com/services
Expand Down
49 changes: 49 additions & 0 deletions spec/combined_rss_feed_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require "spec_helper"
require "combined_rss_feed"

RSpec.describe CombinedRssFeed do
it "combines a given set of feeds into an ordered list by most recent" do
Excon.stub(
{host: "podcast.thoughtbot.com"},
{status: 200, body: giant_robots_feed}
)
Excon.stub(
{host: "bikeshed.thoughtbot.com"},
{status: 200, body: bike_shed_feed}
)

combined_items = described_class.new(
feed_urls: [
"https://podcast.thoughtbot.com/rss",
"https://bikeshed.thoughtbot.com/rss"
]
)
recent = combined_items.take(3)

expect(recent).to include(
have_attributes(
title: "451: Making Time for and Managing Focus",
url: "https://bikeshed.thoughtbot.com/451",
created_at: match_date(Date.new(2024, 12, 17))
),
have_attributes(
title: "450: Javascript-Driven Development?",
url: "https://bikeshed.thoughtbot.com/450",
created_at: match_date(Date.new(2024, 12, 10))
),
have_attributes(
title: "553: The One with Sami and Chad",
url: "https://podcast.thoughtbot.com/553",
created_at: match_date(Date.new(2024, 12, 5))
)
)
end

def giant_robots_feed
File.read("spec/fixtures/giant_robots_feed.xml")
end

def bike_shed_feed
File.read("spec/fixtures/bike_shed_feed.xml")
end
end
114,837 changes: 114,837 additions & 0 deletions spec/fixtures/bike_shed_feed.xml

Large diffs are not rendered by default.

128,515 changes: 128,515 additions & 0 deletions spec/fixtures/giant_robots_feed.xml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
Excon.stubs.clear
end
end

RSpec::Matchers.define :match_date do |expected|
match do |actual|
expect(expected.strftime("%d-%m-%Y")).to eq(actual.strftime("%d-%m-%Y"))
end
end

0 comments on commit ea4937d

Please sign in to comment.