Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Add a rake task to find unused images
Browse files Browse the repository at this point in the history
  • Loading branch information
dshevtsov committed Dec 23, 2021
1 parent 870a722 commit 272337c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rakelib/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,25 @@ namespace :test do
abort 'Fix the reported issues'.red unless output.empty?
puts 'No issues found'.green
end

desc 'Find unused images'
task :unused_images do
puts 'Running a task for finding unused images'.magenta
images = Dir['src/**/*.{png,svg,jpeg,jpg,ico}']
puts "The project contains a total of #{images.size} images."
puts 'Checking for unlinked images...'
Dir['src/**/*.{md,html,js,css}'].each do |file|
# Exclude symmlinks
next if File.symlink? file

images.delete_if { |image| File.read(file).include?(File.basename(image)) }
end

abort 'No unliked images' if images.empty?

images.each do |image|
puts "No links for #{image}".yellow
end
puts "Found #{images.size} dangling images".red
end
end

0 comments on commit 272337c

Please sign in to comment.