Created
September 16, 2011 13:19
-
-
Save inky/1222111 to your computer and use it in GitHub Desktop.
Some useful Jekyll tags for generating RSS/Atom feeds.
This file contains hidden or 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' | |
| 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