I have several websites and would like to show content via RSS like headlines in a Jekyll project. Is it possible to parse external rss feeds with jekyll and use them?
Asked
Active
Viewed 1,120 times
2 Answers
4
Yes. You'd either want to create a plugin to fetch and parse the external feeds during jekyll build
or, plan B, you could always fetch and parse the feeds client-side with AJAX. Since you asked for a Jekyll answer, here's a rough approximation of the former approach:
# Runs during jekyll build
class RssFeedCollector < Generator
safe true
priority :high
def generate(site)
# TODO: Insert code here to fetch RSS feeds
rss_item_coll = null;
# Create a new on-the-fly Jekyll collection called "external_feed"
jekyll_coll = Jekyll::Collection.new(site, 'external_feed')
site.collections['external_feed'] = jekyll_coll
# Add fake virtual documents to the collection
rss_item_coll.each do |item|
title = item[:title]
content = item[:content]
guid = item[:guid]
path = "_rss/" + guid + ".md"
path = site.in_source_dir(path)
doc = Jekyll::Document.new(path, { :site => site, :collection => jekyll_coll })
doc.data['title'] = title;
doc.data['feed_content'] = content;
jekyll_coll.docs << doc
end
end
end
You can then access the collection in your template like so:
{% for item in site.collections['external_feed'].docs %}
<h2>{{ item.title }}</h2>
<p>{{ item.feed_content }}</p>
{% endfor %}
There are a lot of possible variations on the theme but that's the idea.
-
First of all, thank you for helping me out. Can you point me to a website, where I can read more about the **TODO** – fetching RSS with ruby. I know only little ruby. – Phlow Jan 11 '15 at 10:55
-
1I would start with the examples in [Net::HTTP](http://ruby-doc.org/stdlib-2.2.0/libdoc/net/http/rdoc/Net/HTTP.html) or for a simpler approach, check out this question which uses [OpenURI](http://stackoverflow.com/questions/1854207/getting-webpage-content-with-ruby-im-having-troubles). – Jan 11 '15 at 18:17
-
Did you ever get to code this as a plugin (and open source it)? – user569825 Jan 17 '20 at 01:07
-1
Well, I don't think Jekyll per se can do that... because Jekyll is more of a CMS. However, Jekyll is written in Ruby can I believe you can easily run ruby/rake tasks with Jekyll (that's even probably what's being used when you build a Jekyll site), so I believe you should probably do that as a ruby script.

Julien Genestoux
- 31,046
- 20
- 66
- 93