1
0
mirror of https://github.com/bigchaindb/site.git synced 2024-11-28 23:06:20 +01:00
site/_src/_plugins/blog.rb

43 lines
1.3 KiB
Ruby
Raw Normal View History

# 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 "articles"
jekyll_items = Jekyll::Collection.new(site, 'articles')
site.collections['articles'] = jekyll_items
# Add fake virtual documents to the collection
rss_items.items.each do |item|
2017-05-23 21:55:10 +02:00
title = item.title
link = item.link
# Medium hack: get first image in content, then get smaller image size
image = item.content_encoded[/img.*?src="(.*?)"/i,1].gsub(/max\/(.*)\//, "max/500/")
path = '_articles/' + 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['link'] = link
doc.data['image'] = image
jekyll_items.docs << doc
end
rescue
puts "Could not parse blog feed. Are you offline?"
end
end
end