Skip to content

Instantly share code, notes, and snippets.

@inky
Created September 16, 2011 13:19
Show Gist options
  • Select an option

  • Save inky/1222111 to your computer and use it in GitHub Desktop.

Select an option

Save inky/1222111 to your computer and use it in GitHub Desktop.
Some useful Jekyll tags for generating RSS/Atom feeds.
require 'nokogiri'
require 'uri'
module FeedTags
def absolute_url(url, base='/')
return url if url.match /^(javascript|data):/
root = @context.registers[:site].config['home']
URI.join(root, base, url).to_s
end
def date_to_atom(dt)
dt.iso8601
end
def date_to_rss(dt)
dt.rfc2822
end
def portable_html(html, base='/')
doc = Nokogiri::HTML::DocumentFragment.parse html
doc.css('a').each {|a| a['href'] = absolute_url(a['href'], base) }
doc.css('img').each {|img| img['src'] = absolute_url(img['src'], base) }
doc.to_html
end
Liquid::Template.register_filter(FeedTags)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment