Skip to content

Commit

Permalink
Merge pull request #1153 from PRX/feat/episode_footer
Browse files Browse the repository at this point in the history
Episode description footer
  • Loading branch information
kookster authored Dec 2, 2024
2 parents 2a9e8f5 + 7335a8e commit 8f219ec
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/controllers/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def nilified_feed_params
:sonic_id,
:type,
:apple_show_id,
:episode_footer,
itunes_category: [],
itunes_subcategory: [],
feed_tokens_attributes: %i[id label token _destroy],
Expand Down
12 changes: 10 additions & 2 deletions app/helpers/podcasts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ def feed_description(feed, podcast)
[feed.description, podcast.description].detect { |d| d.present? } || ""
end

def episode_description(episode)
if episode.podcast.has_apple_feed?
def episode_description(episode, feed)
description = if episode.podcast.has_apple_feed?
episode.description_safe
else
episode.description_with_default
end

if feed.episode_footer.present?
footer_text = "\n\n#{feed.episode_footer}"
description = description.truncate_bytes(Episode::MAX_DESCRIPTION_BYTES - footer_text.bytesize)
description += footer_text
end

description
end

def full_contact(type, item)
Expand Down
8 changes: 8 additions & 0 deletions app/views/feeds/_form_main.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@
<%= field_help_text t(".help.display_full_episodes_count") %>
</div>
</div>

<div class="col-12 mb-4">
<div class="form-floating input-group">
<%= form.text_field :episode_footer %>
<%= form.label :episode_footer %>
<%= field_help_text t(".help.episode_footer") %>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/podcasts/show.rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ xml.rss "xmlns:atom" => "http://www.w3.org/2005/Atom",
xml.title(ep.title)
xml.pubDate ep.published_at.utc.rfc2822
xml.link ep.url || ep.enclosure_url(@feed)
xml.description { xml.cdata!(episode_description(ep)) }
xml.description { xml.cdata!(episode_description(ep, @feed)) }
# TODO: may not reflect the content_type/file_size of replaced media
xml.enclosure(url: ep.enclosure_url(@feed), type: ep.media_content_type(@feed), length: ep.media_file_size) if ep.media?

Expand Down Expand Up @@ -165,7 +165,7 @@ xml.rss "xmlns:atom" => "http://www.w3.org/2005/Atom",
url: ep.ready_transcript.url)
end

xml.content(:encoded) { xml.cdata!(episode_description(ep)) }
xml.content(:encoded) { xml.cdata!(episode_description(ep, @feed)) }
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ en:
enclosure_prefix: Enclosure Prefix URL
episode_offset_seconds: Episode Publish Offset
file_name: File Name
episode_footer: Episode Description Footer
friendly_titles:
apple: Apple Subscriptions
default: Default RSS Feed
Expand Down Expand Up @@ -822,6 +823,7 @@ en:
enclosure_prefix: If you have an enclosure prefix URL to set a redirect on audio requests for your podcast feed (e.g., podtrac or blubrry), enter it here.
episode_offset_seconds: Instead of episodes immediately showing up in this feed when published, delay their appearance. AKA Windowing.
file_name: The file name used for your private RSS feed.
episode_footer: Text to be included at the end of each episode's description, such as a privacy policy link.
slug: An alphanumeric slug used to identify your feed. Also used in the private feed RSS url.
title: An alternate title for your feed, to distinguish it from the Default Feed
form_overrides:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241116011452_add_footer_to_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFooterToFeeds < ActiveRecord::Migration[7.2]
def change
add_column :feeds, :episode_footer, :string
end
end
1 change: 1 addition & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file removed test/helpers/.keep
Empty file.
27 changes: 27 additions & 0 deletions test/helpers/podcasts_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "test_helper"

class TestHelper
include PodcastsHelper
end

describe PodcastsHelper do
let(:helper) { TestHelper.new }
let(:podcast) { build(:podcast, description: "description") }
let(:feed1) { podcast.default_feed }
let(:feed2) { build(:feed, private: true, podcast: podcast, slug: "adfree", episode_footer: "footer", description: "different") }
let(:episode) { build(:episode, description: "description") }

describe "#feed_description" do
it "gets the feed or podcast description" do
assert_equal "description", feed_description(feed1, podcast)
assert_equal "different", feed_description(feed2, podcast)
end
end

describe "#episode_description" do
it "gets the episode description with a footer" do
assert_equal "description", episode_description(episode, feed1)
assert_equal "description\n\nfooter", episode_description(episode, feed2)
end
end
end

0 comments on commit 8f219ec

Please sign in to comment.