Created
January 10, 2017 15:09
-
-
Save waynegraham/179c916dc3c3d0efd3ea5cf14116904c to your computer and use it in GitHub Desktop.
Import the full RSS feed in to Jekyll (from WordPress)
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
#! /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