Skip to content

Instantly share code, notes, and snippets.

@Meroje
Created July 15, 2012 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Meroje/3116072 to your computer and use it in GitHub Desktop.
Save Meroje/3116072 to your computer and use it in GitHub Desktop.
ruhoh.rb rss compiler
require 'nokogiri'
class Ruhoh
module Compiler
# This rss compiler is provided by David Long
# http://www.davejlong.com/
# https://github.com/davejlong
# Thanks David!
module Rss
# TODO: This renders the page content even though we already need to
# render the content to save to disk. This will be a problem when posts numbers expand. Merge this in later.
def self.run(target, page)
feed = Nokogiri::XML::Builder.new do |xml|
xml.rss(:version => '2.0') {
xml.channel {
xml.title_ Ruhoh::DB.site['title']
xml.link_ Ruhoh::DB.site['config']['production_url']
xml.pubDate_ Time.now
Ruhoh::DB.posts['chronological'].first(Ruhoh::DB.site['config']['rss']['latest'].to_i).each do |post_id|
post = Ruhoh::DB.posts['dictionary'][post_id]
page.change(post_id)
xml.item {
xml.title_ post['title']
xml.link "#{Ruhoh::DB.site['config']['production_url']}#{post['url']}"
xml.pubDate_ post['date']
xml.description_ (post['description'] ? post['description'] : Ruhoh::Converter.convert(page.content, page.id))
}
end
}
}
end
File.open(File.join(target, 'rss.xml'), 'w'){ |p| p.puts feed.to_xml }
end
end #Rss
end #Compiler
end #Ruhoh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment