Sha256: e7a7c5fd4f29d6b2765652e3c0c8291abe264d379de796b53bc508e64c1bb65b
Contents?: true
Size: 1.24 KB
Versions: 5
Compression:
Stored size: 1.24 KB
Contents
module Jekyll require 'rexml/document' require 'time' require "YAML" module RSS #Reads posts from an RSS feed. #It creates a post file for each entry in the RSS. def self.process(source = "rss.xml") #FileUtils.mkdir_p "_posts" content = "" open(source, "r") { |f| content << f.read } doc = REXML::Document.new(content) posts = 0 doc.elements.each("rss/channel/item") do |item| link = item.elements["link"].text name = link.split("/")[-1] name = $1 if name =~ /(.*)\.html/ name = $1 if name =~ /\d+\-(.*)/ #title = item.elements["title"].text content = item.elements["content:encoded"].text timestamp = Time.parse(item.elements["pubDate"].text) filename = "_posts/#{timestamp.strftime("%Y-%m-%d")}-#{name}.html" puts "#{link} -> #{filename}" File.open(filename, "w") do |f| YAML.dump( { "layout" => "post", "name" => name, "title" => item.elements["title"].text, "time" => timestamp, }, f ) f.puts "---\n#{content}" end posts += 1 end puts "Created #{posts} posts!" end end end
Version data entries
5 entries across 5 versions & 1 rubygems