jekyll-to-wordpress/finalize_export.rb
2020-12-08 19:37:51 +01:00

15 lines
595 B
Ruby

data = STDIN.read
# Replace the image paths to be accessible in Wordpress.
# The new path given here is the path for my case: A multi-site blog. The 1970/01
# in the path was determined by setting a date during extract_media.rb.
# Upload a file to your media gallery and look at the image url to determine
# your correct path.
images = data.scan(/(?:src|href)="(\/uploads\/.+?)"/).to_a.map(&:first).uniq
images.each do |path|
data = data.gsub("="#{path}"", "="/wp-content/uploads/sites/5/1970/01/#{File.basename(path)}"")
end
puts data.gsub(/([^>])\n/, "\\1 ")