Skip to content

Instantly share code, notes, and snippets.

@Rocky-Lee
Forked from chloerei/jekyll_image_fetcher.rb
Created December 9, 2013 16:53
Show Gist options
  • Save Rocky-Lee/7875723 to your computer and use it in GitHub Desktop.
Save Rocky-Lee/7875723 to your computer and use it in GitHub Desktop.
# = Usage
# Download to your jekyll site directory, and run it
# `ruby jekyll_image_fetcher.rb`
Dir['_posts/*.md'].each do |path|
content = File.open(path).read
basename = File.basename path, '.md'
content.gsub!(/!\[\]\((.+)\)/) do |m|
url = $1
`mkdir -p images/posts/#{basename}`
`wget #{url} -P images/posts/#{basename}`
m.gsub $1, "/images/posts/#{basename}/#{File.basename url}"
end
File.open(path, 'w') do |file|
file.write content
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment