Created
September 17, 2012 07:19
-
-
Save douo/3736010 to your computer and use it in GitHub Desktop.
ruhoh's compiler plugin use to compile site's rss
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
require 'nokogiri' | |
class Ruhoh | |
module Compiler | |
# the origin rss compiler is provided by David Long | |
# http://www.davejlong.com/ | |
# https://github.com/davejlong | |
# Thanks David! | |
# this rss compiler is modified by Douo | |
# use page.render_content instead of page.render | |
# add some useful tag | |
# todo: add some configuration to site.yml | |
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', | |
'xmlns:dc' => "http://purl.org/dc/elements/1.1/", | |
'xmlns:content' => "http://purl.org/rss/1.0/modules/content/" | |
) { | |
xml.channel { | |
xml.title_ Ruhoh::DB.site['title'] | |
xml.link_ Ruhoh::DB.site['config']['production_url'] | |
xml.description_ Ruhoh::DB.site['tagline'] | |
xml.lastBuildDate_ Time.now.strftime("%a, %d %b %Y %H:%M:%S %z") | |
Ruhoh::DB.posts['chronological'].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_ Time.parse(post['date']).strftime("%a, %d %b %Y %H:%M:%S %z") | |
xml['dc'].creator_ Ruhoh::DB.site['author']['name'] | |
# xml.guid(:isPermalink => 'false'){ | |
# xml.text "#{Ruhoh::DB.site['config']['production_url']}/?id=#{post_id}" | |
# } | |
# append categories and tags | |
post['categories'].each do |c| | |
xml.category { | |
xml.cdata c | |
} | |
end | |
post['tags'].each do |t| | |
xml.category { | |
xml.cdata t | |
} | |
end | |
xml.description_ post['description'] | |
xml['content'].encoded { | |
xml.cdata page.render_content | |
} | |
} | |
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