Skip to content

Conversation

@rosieyohannan
Copy link
Contributor

@rosieyohannan rosieyohannan commented Nov 18, 2025

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

  1. Missing Cross-Component Reference Support - The original extension only checked for:
  • images/myImage.png
  • ROOT:images/myImage.png (module)

But we use cross-component references like:

  • guides:ROOT:images/myImage.png
  1. Regex Pattern

The regex /(image|video)::?([^[]+)/g was matching our images but also some content from CircleCI code blocks, for example: image: cimg/base:2021.04

When it hit YAML image: keys, it would capture everything until the next [ character, creating mangled references that included large chunks of documentation content.

  1. Missing Implicit images/ Directory Handling. In Antora/AsciiDoc, the images/ directory is implicit. References like guides:ROOT:core_dumps.png actually point to modules/ROOT/images/core_dumps.png but the extension wasn't checking both formats.

Fix

Created a custom local extension at extensions/detect-unused-media-extension.js with the following fixes:

  1. Improved Regex Pattern:
  • Matches only non-whitespace characters (\S+?)
  • Stops at [ or end of line
  • Uses multiline mode to prevent cross-line matching
  1. Docker Image Filtering

  2. 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.

@rosieyohannan rosieyohannan marked this pull request as ready for review November 18, 2025 11:24
@rosieyohannan rosieyohannan requested review from a team as code owners November 18, 2025 11:24
@rosieyohannan rosieyohannan merged commit 8586508 into main Nov 19, 2025
2 of 3 checks passed
@rosieyohannan rosieyohannan deleted the set-up-extension-unused-media branch November 19, 2025 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants