Skip to content

Instantly share code, notes, and snippets.

@kremalicious
Created May 30, 2016 12:48
Show Gist options
  • Select an option

  • Save kremalicious/025bb40d49d51ca2cfa169f956820967 to your computer and use it in GitHub Desktop.

Select an option

Save kremalicious/025bb40d49d51ca2cfa169f956820967 to your computer and use it in GitHub Desktop.
# http://stackoverflow.com/a/27850727/733677
require 'open-uri'
require 'rss'
module Jekyll
# Runs during jekyll build
class RssFeedCollector < Generator
safe true
priority :high
def generate(site)
rss_items = RSS::Parser.parse(open('https://blog.chartmogul.com/feed/').read, false)
# Create a new on-the-fly Jekyll collection called "external_feed"
jekyll_items = Jekyll::Collection.new(site, 'external_feed')
site.collections['external_feed'] = jekyll_items
# Add fake virtual documents to the collection
rss_items.items.each do |item|
title = item.title
#content = item.description
guid = item.guid
path = "_rss/" + title + ".md"
path = site.in_source_dir(path)
doc = Jekyll::Document.new(path, { :site => site, :collection => jekyll_items })
doc.data['title'] = title;
#doc.data['feed_content'] = content;
jekyll_items.docs << doc
end
end
end
end
{% for item in site.collections['external_feed'].docs %}
<h2>{{ item.title }}</h2>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment