Skip to content

Commit

Permalink
COMDOX-1150: Add rake tasks :unused_images and :unused_includes
Browse files Browse the repository at this point in the history
  • Loading branch information
dshevtsov committed Jan 28, 2025
1 parent e0015c4 commit 956bb32
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions _jekyll/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,57 @@ desc 'Render the templated files'
task :render do
sh '_scripts/render'
end

desc 'Find unused images.'
task :unused_images do
puts 'Running a task for finding unused images (png,svg,jpeg,jpg,ico)'.magenta
images = FileList['../help/**/*.{png,svg,jpeg,jpg,ico}']

puts "The project contains a total of #{images.size} images."

puts 'Checking for unlinked images...'
Dir['../help/**/*.{md}'].each do |file|
# Exclude symmlinks
next if File.symlink? file

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

if images.empty?
puts 'No unlinked images'.green
else
images.each do |image|
puts "No links for #{image}".yellow
end
puts "Found #{images.size} dangling images".red
end
end

desc 'Find unused includes.'
task :unused_includes do
puts 'Running a task to find unused _includes'.magenta
includes = FileList['../help/_includes/**/*']

puts "The project contains a total of #{includes.size} includes"

# snippets.md is expected and should not be removed based on the way the snippets functionality was designed for ExL.
# See https://experienceleague.corp.adobe.com/docs/authoring-guide-exl/using/authoring/includes-snippets.html?lang=en#creating-snippets.
exclude = '../help/_includes/snippets.md'
includes.exclude(exclude) if exclude

Dir['../help/**/*.{md}'].each do |file|
next if File.symlink? file

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

if includes.empty?
puts 'No unlinked includes'.green
else
puts 'The following includes are not linked:'
includes.each do |include|
puts "No links for #{include}".yellow
end
puts "Found #{includes.size} unlinked includes".red
end
end

0 comments on commit 956bb32

Please sign in to comment.