-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for external blog posts (#647)
* Add support for external blog posts * Cosmetic fixes
- Loading branch information
1 parent
f7dd7f6
commit 42abefc
Showing
5 changed files
with
81 additions
and
21 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,36 @@ | ||
require 'feedjira' | ||
require 'httparty' | ||
require 'jekyll' | ||
|
||
module ExternalPosts | ||
class ExternalPostsGenerator < Jekyll::Generator | ||
safe true | ||
priority :high | ||
|
||
def generate(site) | ||
if site.config['external_sources'] != nil | ||
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; | ||
site.collections['posts'].docs << doc | ||
end | ||
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
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