mirror of
https://github.com/bigchaindb/site.git
synced 2024-11-01 15:55:36 +01:00
41 lines
1.2 KiB
Ruby
41 lines
1.2 KiB
Ruby
# http://stackoverflow.com/a/27850727/733677
|
|
|
|
require 'open-uri'
|
|
require 'rss'
|
|
require 'simple-rss'
|
|
|
|
module Jekyll
|
|
|
|
# Runs during jekyll build
|
|
class RssFeedCollector < Generator
|
|
safe true
|
|
priority :high
|
|
def generate(site)
|
|
|
|
rss_items = SimpleRSS.parse open('https://blog.bigchaindb.com/feed/')
|
|
|
|
# Create a new on-the-fly Jekyll collection called "blog"
|
|
jekyll_items = Jekyll::Collection.new(site, 'blog')
|
|
site.collections['blog'] = jekyll_items
|
|
|
|
# Add fake virtual documents to the collection
|
|
rss_items.items.each do |item|
|
|
title = item.title
|
|
description = item.description
|
|
link = item.link
|
|
image = item.media_content_url
|
|
path = "_rss/" + title.to_s.gsub(':','_') + ".md"
|
|
path = site.in_source_dir(path)
|
|
doc = Jekyll::Document.new(path, site: site, collection: jekyll_items)
|
|
doc.data['title'] = title
|
|
doc.data['description'] = description
|
|
doc.data['link'] = link
|
|
doc.data['image'] = image
|
|
jekyll_items.docs << doc
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
end
|