-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7dd7f6
commit 8d0c2a6
Showing
4 changed files
with
69 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'feedjira' | ||
require 'httparty' | ||
require 'jekyll' | ||
|
||
module ExternalPosts | ||
class ExternalPostsGenerator < Jekyll::Generator | ||
safe true | ||
priority :high | ||
|
||
def generate(site) | ||
site.config['external_sources'].each do |src| | ||
p "Fetching external posts from #{src['name']}:" | ||
xml = HTTParty.get(src['rss_url']).body | ||
feed = Feedjira.parse(xml) | ||
feed.entries.each do |e| | ||
p "...fetching #{e.url}" | ||
slug = e.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') | ||
path = site.in_source_dir("_posts/#{slug}.md") | ||
doc = Jekyll::Document.new(path, { :site => site, :collection => site.collections['posts'] }) | ||
doc.data['external_source'] = src['name']; | ||
doc.data['feed_content'] = e.content; | ||
doc.data['title'] = "#{e.title}"; | ||
doc.data['description'] = e.summary; | ||
doc.data['date'] = e.published; | ||
doc.data['redirect'] = e.url; | ||
doc.data['categories'] = ["#{src['name']}"]; | ||
site.collections['posts'].docs << doc | ||
end | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters