-
-
Save digitaljhelms/962889 to your computer and use it in GitHub Desktop.
finds unused image assets in a website project.
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
#!/usr/bin/env ruby | |
require 'fileutils' | |
files = Dir['**/*.{htm,html,shtml,php,css,js}'] | |
images = Dir['**/*.{jpg,png,gif,bmp}'] | |
puts "#{images.size} images found & #{files.size} files found to search against" | |
content = "" | |
files.each do |filename| | |
content << File.read(filename) | |
end | |
images.each do |filename| | |
basename = File.basename filename | |
dirname = File.dirname filename | |
image_not_used = content !~ /\b#{basename}\b/ | |
if image_not_used | |
FileUtils.mkdir_p "../unused/#{dirname}" | |
FileUtils.mv filename, "../unused/#{filename}" | |
puts "Image '#{filename}' moved to '../unused' folder" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment