Generating a Blogroll from Your .opml File

I’ve been thinking about having a blogroll on my site for a little while. If nothing else, I owe so much to smarter people on the internet, the best thing I could do for others is to show where some of the connecting dots are that eventually become these posts.

I had been puzzling over how to connect my actual act of reading in my RSS reader… so I took my .opml file out of Reeder1 and I exported it into my source folder.

I made a helper that used nokogiri to select a “folder” in the opml using xpath, and printed that out sorted by name. Hey presto, a quick blogroll that actually can update with my reading!

def blogroll(src = './Feeds.opml')
  File.open(src) do |file|
    Nokogiri::XML(file)
      .xpath("//outline[@title='blogroll']/outline")
      .map{|p| p.attributes }
      .sort_by{|p| p['title'].value.downcase }
  end
end

Then in erb, it’s as simple as displaying the fields that I want from the xml.

<% blogroll().each do |blog| %>
  <h2><%= blog['title'] %></h2>
  <a href="<%= blog['htmlUrl'] %>"><%= blog['htmlUrl'] %></a>
<% end %>

If I still was using newsboat, I probably could automate this and do fancy things, but anywho. If I’m reading a blog in my feed-reader and think it’s worth representing here, I can simply move it to my ‘blogroll’ folder and re-export the OPML.

I’ll figure out where I want it to appear in the navigation eventually, but until then you can see it at /blogroll.


  1. my current RSS reader, yes I dropped newsboat, don’t @ me.