Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a very simple RSS feed using builder.

  • Loading branch information...
commit d113d155008176facf7bfe19f916a8bfc8756700 1 parent c3563c0
@LindseyB authored
Showing with 37 additions and 2 deletions.
  1. +1 −0  Gemfile
  2. +2 −0  Gemfile.lock
  3. +31 −2 blog.rb
  4. +3 −0  views/_header.haml
View
1  Gemfile
@@ -8,3 +8,4 @@ gem 'thin'
gem 'rake'
gem 'haml'
gem 'redcarpet'
+gem 'builder'
View
2  Gemfile.lock
@@ -2,6 +2,7 @@ GEM
remote: http://rubygems.org/
specs:
backports (2.6.4)
+ builder (3.0.4)
daemons (1.1.6)
eventmachine (0.12.10)
haml (3.1.4)
@@ -35,6 +36,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ builder
haml
rake
redcarpet
View
33 blog.rb
@@ -16,12 +16,16 @@ def title
"#{TITLE} » #{@title}"
end
- def latest_posts
+ def latest_posts(content = false)
ret = []
Dir.glob("posts/*.md") do |post|
post = post[/posts\/(.*?).md$/,1]
p = Post.new(post)
- ret << {:id => post, :title => p.title, :date => p.formatted_date, :url => "/posts/#{post}"}
+ if content
+ ret << {:id => post, :title => p.title, :date => p.formatted_date, :url => "/posts/#{post}", :content => p.content}
+ else
+ ret << {:id => post, :title => p.title, :date => p.formatted_date, :url => "/posts/#{post}"}
+ end
end
ret.sort{|x,y| y[:id] <=> x[:id]}
end
@@ -65,4 +69,29 @@ def partial(page, options={})
haml :archive
end
+
+ get '/rss.xml' do
+ @posts = latest_posts(true)
+
+ builder do |xml|
+ xml.instruct! :xml, :version => '1.0'
+ xml.rss :version => "2.0" do
+ xml.channel do
+ xml.title "Lindsey Bieda"
+ xml.description "Lindsey Bieda's blog."
+ xml.link "http://rarlindseysmash.com"
+
+ @posts.each do |post|
+ xml.item do
+ xml.title post[:title]
+ xml.link "http://rarlindseysmash#{post[:url]}"
+ xml.description "<![CDATA[ #{post[:content]} ]]>"
+ xml.pubDate Time.parse(post[:date].to_s).rfc822()
+ xml.guid "http://rarlindseysmash#{post[:url]}"
+ end
+ end
+ end
+ end
+ end
+ end
end
View
3  views/_header.haml
@@ -16,5 +16,8 @@
%li
%a{:href=>"http://www.goodreads.com/LindseyBieda"}
%img{:src=>"/images/goodreads.png", :alt=>"goodreads"}
+ %li
+ %a{:href=>"/rss.xml"}
+ %img{:src=>"/images/rss.png", :alt=>"rss"}
Please sign in to comment.
Something went wrong with that request. Please try again.