Created
April 26, 2013 20:41
-
-
Save seven1m/5470301 to your computer and use it in GitHub Desktop.
Reads in source files in a Jekyll blog that were imported from a Posterous blog and: 1) downloads Posterous-hosted assets locally and 2) replaces URLs with local ones.
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
require 'open-uri' | |
URL = /https?:\/\/getfile\d*\.posterous\.com[^"]*/ | |
posts = Dir['source/_posts/*'].to_a | |
posts.each do |path| | |
post = File.read(path) | |
post.gsub!(URL).each do |url| | |
data = open(url).read | |
name = File.split(url).last | |
filename = File.join('source/images', name) | |
raise "#{filename} exists" if File.exist?(filename) | |
puts filename | |
File.open(filename, 'wb') { |f| f.write(data) } | |
"/images/#{name}" | |
end | |
File.open(path, 'w') { |f| f.write(post) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment