Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Created January 10, 2017 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save waynegraham/179c916dc3c3d0efd3ea5cf14116904c to your computer and use it in GitHub Desktop.
Save waynegraham/179c916dc3c3d0efd3ea5cf14116904c to your computer and use it in GitHub Desktop.
Import the full RSS feed in to Jekyll (from WordPress)
#! /usr/bin/env ruby
require 'rss'
require 'rss/2.0'
require 'open-uri'
require 'fileutils'
require 'safe_yaml'
url = 'https://www.diglib.org/topics/ndsa/feed/'
open(url) do |rss|
feed = RSS::Parser.parse(rss)
feed.items.each do |item|
formatted_date = item.date.strftime('%Y-%m-%d')
post_name = item.title.split(%r{ |!|/|:|&|-|$|,}).map do |i|
i.downcase if i != ''
end.compact.join('-')
name = "#{formatted_date}-#{post_name}"
header = {
'layout' => 'post',
'title' => item.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_encoded
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment