Sha256: acd36abd1d675ce3bf6f72006d52da566b535d69a60f0887c3eb1e2df21e1f37
Contents?: true
Size: 893 Bytes
Versions: 2
Compression:
Stored size: 893 Bytes
Contents
# Require core library require 'middleman-core' # Extension namespace class MediumExtension < ::Middleman::Extension option :source, 'https://blog.continuum.cl/feed', 'https://medium.com/feed/your-account' expose_to_template :fetch_medium_posts def initialize(app, options_hash={}, &block) super require 'rss' require 'nokogiri' end def fetch_medium_posts medium_rss_to_hash(open(options.source).read) end def medium_rss_parser(feed) posts = [] rss = RSS::Parser.parse(feed, false).items rss.each do |item| posts.push(rss_item_to_hash(item)) end posts end def rss_item_to_hash(item) document = Nokogiri::HTML.fragment(item.content_encoded) { title: item.title, date: item.pubDate, url: item.link, category: item&.category&.content, img: document&.search('img')&.first['src'] } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
middleman-medium-0.0.2 | lib/middleman-medium/extension.rb |
middleman-medium-0.0.1 | lib/middleman-medium/extension.rb |