Created
January 8, 2020 09:18
-
-
Save danhalliday/a21fb42744db2d4b3ed60800ec808984 to your computer and use it in GitHub Desktop.
Quick Podcast Feed with Ruby’s Builder Gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xml.instruct! :xml, version: "1.0" | |
rss_attributes = { | |
"version" => "2.0", | |
"xmlns:dc" => "http://purl.org/dc/elements/1.1/", | |
"xmlns:sy" => "http://purl.org/rss/1.0/modules/syndication/", | |
"xmlns:atom" => "http://www.w3.org/2005/Atom", | |
"xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", | |
"xmlns:content" => "http://purl.org/rss/1.0/modules/content/", | |
"xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd", | |
"xmlns:media" => "http://search.yahoo.com/mrss/" | |
} | |
xml.rss rss_attributes do | |
xml.channel do | |
xml.title podcast.title | |
xml.language "en-GB" | |
xml.description podcast.description | |
xml.link podcast_feed_url | |
xml.atom :link, href: podcast_feed_url, rel: "self", type: "application/rss+xml" | |
xml.itunes :author, podcast.author.name | |
xml.itunes :subtitle, podcast.subtitle | |
xml.itunes :explicit, "clean" | |
xml.itunes :category, text: podcast.category | |
xml.itunes :image, href: podcast.artwork.url(w: 1500, h: 1500, fit: :crop) | |
xml.itunes :owner do | |
xml.itunes :name, podcast.owner.name | |
xml.itunes :email, podcast.email | |
end | |
podcast.episodes.each do |episode| | |
xml.item do | |
xml.title episode.title | |
xml.description episode.description | |
xml.pubDate episode.date.rfc2822 | |
xml.guid podcast_episode_url(episode), isPermaLink: true | |
xml.link podcast_episode_url(episode) | |
xml.itunes :author, episode.author.name | |
xml.itunes :subtitle, episode.subtitle | |
xml.itunes :duration, episode.audio.duration | |
xml.itunes :image, href: episode.artwork.url(w: 1500, h: 1500, fit: :crop) | |
xml.itunes :explicit, "clean" | |
xml.enclosure url: episode.audio.url, length: episode.audio.size, type: "audio/mpeg" | |
xml.media :content, url: episode.audio.url, type: "audio/mpeg" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment