Skip to content

Commit

Permalink
Remove references to keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed May 9, 2024
1 parent 78d6e33 commit 40e7980
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 68 deletions.
22 changes: 4 additions & 18 deletions app/models/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class Episode < ApplicationRecord

acts_as_paranoid

serialize :categories, JSON
serialize :keywords, JSON
serialize :overrides, HashSerializer

belongs_to :podcast, -> { with_deleted }, touch: true
Expand Down Expand Up @@ -224,15 +222,11 @@ def overrides
end

def categories
self[:categories] ||= []
self[:categories] || []
end

def categories=(cats)
self[:categories] = Array(cats).reject(&:blank?)
end

def keywords
self[:keywords] ||= []
self[:categories] = sanitize_keywords(cats, false).presence
end

def copy_media(force = false)
Expand Down Expand Up @@ -295,26 +289,18 @@ def set_external_keyword

identifiers = []
%i[published_at guid].each do |attr|
identifiers << sanitize_keyword(send(attr), 10)
identifiers << sanitize_keyword(send(attr), 10, true)
end
identifiers << sanitize_keyword(title || "undefined", 20)
identifiers << sanitize_keyword(title || "undefined", 20, true)
self.keyword_xid = identifiers.join("_")
end

def sanitize_keyword(kw, length)
kw.to_s.downcase.gsub(/[^ a-z0-9_-]/, "").gsub(/\s+/, " ").strip.slice(
0,
length
)
end

def sanitize_text
self.description = sanitize_white_list(description) if description_changed?
self.content = sanitize_white_list(content) if content_changed?
self.subtitle = sanitize_text_only(subtitle) if subtitle_changed?
self.summary = sanitize_links_only(summary) if summary_changed?
self.title = sanitize_text_only(title) if title_changed?
self.keywords = keywords.map { |kw| sanitize_keyword(kw, kw.length) }
end

def description_with_default
Expand Down
2 changes: 1 addition & 1 deletion app/models/episode_entry_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class EpisodeEntryHandler
ENTRY_ATTRIBUTES = %w[author block categories content description explicit
feedburner_orig_enclosure_link feedburner_orig_link is_closed_captioned
is_perma_link keywords position subtitle summary title url
is_perma_link position subtitle summary title url
season_number episode_number clean_title].freeze

attr_accessor :episode
Expand Down
37 changes: 9 additions & 28 deletions app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,6 @@ def feed_episodes
include_in_feed
end

def episode_categories_include?(ep, match_tags)
tags = match_tags.map { |cat| normalize_category(cat) }
cats = (ep || []).categories.map { |cat| normalize_category(cat) }
(tags & cats).length > 0
end

def normalize_category(cat)
cat.to_s.downcase.gsub(/[^ a-z0-9_-]/, "").gsub(/\s+/, " ").strip
end

def publish_to_apple?
!!apple_config&.publish_to_apple?
end
Expand All @@ -180,29 +170,20 @@ def exclude_tags=(tags)
self[:exclude_tags] = tags.blank? ? nil : tags
end

def use_include_tags?
!include_tags.blank?
end

def use_exclude_tags?
!exclude_tags.blank?
end

def filtered_episodes
eps = podcast.episodes.published_by(episode_offset_seconds.to_i)

eps =
if use_include_tags?
eps.select { |ep| episode_categories_include?(ep, include_tags) }
else
eps
end
if include_tags.present?
kws = sanitize_keywords(include_tags, true)
eps = eps.select { |e| (sanitize_keywords(e.categories, true) & kws).any? }
end

if use_exclude_tags?
eps.reject { |ep| episode_categories_include?(ep, exclude_tags) }
else
eps
if exclude_tags.present?
kws = sanitize_keywords(exclude_tags, true)
eps = eps.reject { |e| (sanitize_keywords(e.categories, true) & kws).any? }
end

eps
end

def enclosure_template
Expand Down
10 changes: 8 additions & 2 deletions app/models/podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class Podcast < ApplicationRecord

acts_as_paranoid

serialize :categories, JSON
serialize :keywords, JSON
serialize :restrictions, JSON

has_one :default_feed, -> { default }, class_name: "Feed", validate: true, autosave: true, inverse_of: :podcast
Expand Down Expand Up @@ -155,6 +153,14 @@ def managing_editor
"#{managing_editor_email} (#{managing_editor_name})"
end

def categories
self[:categories] || []
end

def categories=(cats)
self[:categories] = sanitize_keywords(cats, false).presence
end

def feed_episodes
default_feed.feed_episodes
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/podcast_feed_handler.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class PodcastFeedHandler
FEED_ATTRS = %w[ complete copyright description explicit keywords language
FEED_ATTRS = %w[ complete copyright description explicit language
subtitle summary title update_frequency update_period
author managing_editor new_feed_url owners ].freeze

Expand Down
1 change: 0 additions & 1 deletion app/representers/api/episode_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Api::EpisodeRepresenter < Api::BaseRepresenter
property :is_closed_captioned
property :is_perma_link
property :include_in_feed?, as: :is_feed_ready
property :keywords
property :categories
property :position

Expand Down
1 change: 0 additions & 1 deletion app/representers/api/podcast_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class Api::PodcastRepresenter < Api::BaseRepresenter
property :managing_editor_email, as: :email
end

collection :keywords
collection :categories
collection :restrictions

Expand Down
6 changes: 3 additions & 3 deletions app/views/podcasts/show.rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ xml.rss "xmlns:atom" => "http://www.w3.org/2005/Atom",
xml.itunes(:summary) { xml.cdata!(itunes_summary(@podcast)) }
end

xml.itunes :keywords, @podcast.keywords.join(",") unless @podcast.keywords.blank?
# xml.itunes :keywords, @podcast.keywords.join(",") unless @podcast.keywords.blank?

xml.media :copyright, @podcast.copyright unless @podcast.copyright.blank?
xml.media :thumbnail, url: @feed_image.url if @feed_image
xml.media :keywords, @podcast.keywords.join(",") unless @podcast.keywords.blank?
# xml.media :keywords, @podcast.keywords.join(",") unless @podcast.keywords.blank?

cat = @itunes_categories.first.try(:name)
xml.media :category, cat, scheme: "http://www.itunes.com/dtds/podcast-1.0.dtd" unless cat.blank?
Expand Down Expand Up @@ -152,7 +152,7 @@ xml.rss "xmlns:atom" => "http://www.w3.org/2005/Atom",
xml.itunes :image, href: @itunes_image.url
end

xml.itunes :keywords, ep.keywords.join(",") unless ep.keywords.blank?
# xml.itunes :keywords, ep.keywords.join(",") unless ep.keywords.blank?
xml.itunes(:isClosedCaptioned, "Yes") if ep.is_closed_captioned

if ep.media?
Expand Down
1 change: 0 additions & 1 deletion test/factories/podcast_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
owner_email { "jesse@maximumfun.org" }
categories { ["Humor", "Entertainment"] }
explicit { "true" }
keywords { ["laffs", "comedy", "good-times"] }
update_period { "weekly" }
update_frequency { 1 }
update_base { 1.year.ago }
Expand Down
1 change: 0 additions & 1 deletion test/models/episode_entry_handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
assert_equal episode.summary,
"Few forms of contemporary architecture draw as much criticism as the McMansion, a particular type of oversized house that people love to hate. McMansions usually feature 3,000 or more square feet of space and fail to embody a cohesive style or interact with their environment. Kate Wagner, architecture critic and creator of McMansion Hell, is on a mission to illustrate just why these buildings are so terrible. McMansion Hell: The Devil is in the Details Support 99pi and Radiotopia today! Be part of the 5000 backer FreshBooks challenge: FreshBooks will donate $40,000 to Radiotopia if we get 5000 total new donations during this drive. FreshBooks makes intuitive and beautiful cloud accounting software for small businesses."
assert_equal episode.explicit, "false"
assert_equal episode.keywords, ["roman mars", "kate wagner"]
assert_equal episode.description,
"Few forms of contemporary architecture draw as much criticism as the McMansion, a particular type of oversized house that people love to hate. McMansions usually feature 3,000 or more square feet of space and fail to embody a cohesive style or interact with their environment. Kate Wagner, architecture critic and creator of McMansion Hell, is on a mission to illustrate just why these buildings are so terrible. McMansion Hell: The Devil is in the Details Support 99pi and Radiotopia today! Be part of the 5000 backer FreshBooks challenge: FreshBooks will donate $40,000 to Radiotopia if we get 5000 total new donations during this drive. FreshBooks makes intuitive and beautiful cloud accounting software for small businesses."
assert_equal episode.categories,
Expand Down
16 changes: 9 additions & 7 deletions test/models/episode_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@
assert_includes episode.keyword_xid, "241 its a title yay"
end

it "strips non-alphanumeric characters from all keywords" do
episode.update(keywords: ["Here's John,ny!?"])
episode.run_callbacks :save do
episode.save
end
refute_nil episode.reload.keywords
episode.keywords.each { |k| refute_match(/['?!,]/, k) }
it "sanitizes categories" do
e = build_stubbed(:episode)

e.categories = []
assert_equal [], e.categories
assert_nil e[:categories]

e.categories = ["foo", " Foo ", "BAR ", " foo", "!@ $?"]
assert_equal ["foo", "Foo", "BAR", "!@ $?"], e.categories
end

it "has a valid itunes episode type" do
Expand Down
11 changes: 11 additions & 0 deletions test/models/podcast_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@
assert_nil p[:link]
end

it "sanitizes categories" do
p = build_stubbed(:podcast)

p.categories = []
assert_equal [], p.categories
assert_nil p[:categories]

p.categories = ["foo", " Foo ", "BAR ", " foo", "!@ $?"]
assert_equal ["foo", "Foo", "BAR", "!@ $?"], p.categories
end

describe "publishing" do
it "creates a publish job on publish" do
PublishingPipelineState.stub(:start_pipeline!, "published!") do
Expand Down
4 changes: 0 additions & 4 deletions test/representers/api/podcast_representer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
assert_equal json["owner"]["email"], "jesse@maximumfun.org"
end

it "includes keywords" do
assert_includes json["keywords"], "laffs"
end

it "includes categories" do
assert_includes json["categories"], "Humor"
end
Expand Down

0 comments on commit 40e7980

Please sign in to comment.