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

Add support for Podcast RSS feed imports #413

Merged
merged 10 commits into from Apr 24, 2021
13 changes: 13 additions & 0 deletions lib/jekyll-import/importers/rss.rb
Expand Up @@ -6,6 +6,7 @@ class RSS < Importer
def self.specify_options(c)
c.option "source", "--source NAME", "The RSS file or URL to import"
c.option "tag", "--tag NAME", "Add a tag to posts"
c.option "render_audio", "--render_audio", "Render <audio> element as necessary"
end

def self.validate(options)
Expand All @@ -32,6 +33,7 @@ def self.process(options)
source = options.fetch("source")
frontmatter = options.fetch("frontmatter", [])
body = options.fetch("body", ["description"])
render_audio = options.fetch("render_audio", false)

content = ""
open(source) { |s| content = s.read }
Expand All @@ -43,6 +45,7 @@ def self.process(options)
formatted_date = item.date.strftime("%Y-%m-%d")
post_name = Jekyll::Utils.slugify(item.title, :mode => "latin")
name = "#{formatted_date}-#{post_name}"
audio = render_audio && item.enclosure.url

header = {
"layout" => "post",
Expand All @@ -69,6 +72,16 @@ def self.process(options)
File.open("_posts/#{name}.html", "w") do |f|
f.puts header.to_yaml
f.puts "---\n\n"

if audio
f.puts <<~HTML
<audio controls="">
<source src="#{audio}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
HTML
end

f.puts output
end
end
Expand Down