Module: Jekyll::MigrateRSS

Defined in:
lib/jekyll/migrators/rss.rb

Class Method Summary collapse

Class Method Details

.process(source) ⇒ Object

The ‘source` argument may be a URL or a local file.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jekyll/migrators/rss.rb', line 22

def self.process(source)
  content = ""
  open(source) { |s| content = s.read }
  rss = RSS::Parser.parse(content, false)

  raise "There doesn't appear to be any RSS items at the source (#{source}) provided." unless rss

  rss.items.each do |item|
    formatted_date = item.date.strftime('%Y-%m-%d')
    post_name = item.title.split(%r{ |!|/|:|&|-|$|,}).map { |i| i.downcase if i != '' }.compact.join('-')
    name = "#{formatted_date}-#{post_name}" 

    header = {
      'layout' => 'post',
      'title' => item.title
    }

    File.open("_posts/#{name}.html", "w") do |f|
      f.puts header.to_yaml
      f.puts "---\n"
      f.puts item.description
    end
  end
end