mirror of
https://github.com/ToshioCP/Gtk4-tutorial.git
synced 2025-01-12 20:03:28 +01:00
19 lines
516 B
Ruby
19 lines
516 B
Ruby
require 'fileutils'
|
|
include FileUtils
|
|
|
|
def cp_images srcmdfiles, dst_dir
|
|
mkdir_p(dst_dir) unless Dir.exist?(dst_dir)
|
|
images = srcmdfiles.map do |file|
|
|
d = File.dirname(file)
|
|
f = File.read(file)
|
|
f = f.gsub(/^ .*\n/,'')
|
|
f = f.gsub(/^~~~.*?^~~~\n/m,'')
|
|
imgs = f.scan(/!\[.*?\]\((.*?)\)/).flatten.uniq
|
|
imgs.map{|img| File.absolute_path("#{d}/#{img}")}
|
|
end
|
|
images = images.flatten.sort.uniq
|
|
images.each do |src|
|
|
dst = "#{dst_dir}/#{File.basename(src)}"
|
|
cp(src, dst)
|
|
end
|
|
end
|