Class: Jekyll::JekyllDisplayMediumPosts

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll-display-medium-posts.rb

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jekyll-display-medium-posts.rb', line 7

def generate(site)
  jekyll_coll = Jekyll::Collection.new(site, 'medium_posts')
  site.collections['medium_posts'] = jekyll_coll
Feedjira::Feed.fetch_and_parse("https://medium.com/feed/@" + ENV["MEDIUM_USERNAME"]).entries.each do |e|
    p "Title: #{e.title}, published on Medium #{e.url} #{e}"
    title = e[:title]
    content = e[:content]
    guid = e[:url]
    path = "./medium_posts/" + title + ".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;
    doc.data['medium_link'] = e.url;
    jekyll_coll.docs << doc
  end
end