Skip to content

Instantly share code, notes, and snippets.

@seven1m
Created April 26, 2013 20:41
Show Gist options
  • Save seven1m/5470301 to your computer and use it in GitHub Desktop.
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.
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