Last active
December 24, 2015 05:19
-
-
Save chloerei/6750044 to your computer and use it in GitHub Desktop.
Fetch images and replace link in markdown posts.
This file contains hidden or 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
# = 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