Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add importer for cached Google Reader RSS feeds #36

Merged
merged 1 commit into from
Jul 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/jekyll/commands/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Import < Command
:drupal7 => 'Drupal7',
:enki => 'Enki',
:joomla => 'Joomla',
:google_reader => 'GoogleReader',
:marley => 'Marley',
:mephisto => 'Mephisto',
:mt => 'MT',
Expand Down
61 changes: 61 additions & 0 deletions lib/jekyll/jekyll-import/google_reader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Usage:
# (Local file)
# ruby -r 'jekyll/jekyll-import/rss' -e "JekyllImport::GoogleReader.process(:source => './somefile/on/your/computer.xml')"

require 'rss'
require 'open-uri'
require 'fileutils'
require 'safe_yaml'

require 'rexml/document'
require 'date'

module JekyllImport
module GoogleReader
def self.validate(options)
if !options[:source]
abort "Missing mandatory option --source."
end
end

# Process the import.
#
# source - a URL or a local file String.
#
# Returns nothing.
def self.process(options)
validate(options)

source = options[:source]

open(source) do |content|
feed = RSS::Parser.parse(content)

raise "There doesn't appear to be any RSS items at the source (#{source}) provided." unless feed

feed.items.each do |item|
title = item.title.content.to_s
formatted_date = Date.parse(item.published.to_s)
post_name = title.split(%r{ |!|/|:|&|-|$|,}).map do |i|
i.downcase if i != ''
end.compact.join('-')
name = "#{formatted_date}-#{post_name}"

header = {
'layout' => 'post',
'title' => title
}

FileUtils.mkdir_p("_posts")

File.open("_posts/#{name}.html", "w") do |f|
f.puts header.to_yaml
f.puts "---\n\n"
f.puts item.content.content.to_s
end
end
end
end
end
end