Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Episode description footer #1153

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
: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.footer.present?
footer_text = "\n\n#{feed.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 :footer %>
<%= form.label :footer %>
<%= field_help_text t(".help.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
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.
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, :footer, :string
end
end
3 changes: 2 additions & 1 deletion 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", 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
Loading