Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created August 11, 2020 05:33
Show Gist options
  • Save jubishop/9362a0f3e22a424d5823a5d2a734ad4a to your computer and use it in GitHub Desktop.
Save jubishop/9362a0f3e22a424d5823a5d2a734ad4a to your computer and use it in GitHub Desktop.
require 'down'
src = File.open("about-me.html", "r") { |file| file.read }
count = 0
src.gsub!(/(src|data-flickity-lazyload)="(\S+)"/) { |match|
extension = if ($2.include? 'jpg' or $2.include? 'jpeg')
"jpg"
elsif ($2.include? 'png')
"png"
elsif ($2.include? 'gif')
"gif"
end
if extension.nil?
match
else
file = "img/#{count}.#{extension}"
Down.download($2, destination:"./#{file}")
count += 1
"#{$1}=\"#{file}\""
end
}
File.open("about-me.html", "w+") { |file| file.puts src }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment