Add extension to detect unused images #9767
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Unused Media Detection Extension
Problem - we have unused images that need to be archived
There is an extension to detect unused media: https://github.com/bonitasoft/antora-detect-unused-media-extension but it flags many images as unused that were actually in use.
Issues with the existing extenstion
images/myImage.pngROOT:images/myImage.png(module)But we use cross-component references like:
guides:ROOT:images/myImage.pngThe regex
/(image|video)::?([^[]+)/gwas matching our images but also some content from CircleCI code blocks, for example:image: cimg/base:2021.04When it hit YAML
image:keys, it would capture everything until the next[character, creating mangled references that included large chunks of documentation content.images/Directory Handling. In Antora/AsciiDoc, theimages/directory is implicit. References likeguides:ROOT:core_dumps.pngactually point tomodules/ROOT/images/core_dumps.pngbut the extension wasn't checking both formats.Fix
Created a custom local extension at
extensions/detect-unused-media-extension.jswith the following fixes:(\S+?)[or end of lineDocker Image Filtering
Comprehensive Path Checking
The extension now checks 6 different reference formats for each image:
images/myImage.png(full path with images/)myImage.png(without images/ - implicit)ROOT:images/myImage.png(module-qualified with images/)ROOT:myImage.png(module-qualified without images/)guides:ROOT:images/myImage.png(component-qualified with images/)guides:ROOT:myImage.png(component-qualified without images/)Archived Unused Images
Created
archive/images/directory and moved unused images to archive. We can be sure this is working because the build will fail if a referenced image is missing.