Unused Images Finder
A Deno script to identify unused images in a Markdown-based project.
Purpose
This script scans all Markdown files in a specified folder and identifies images in an images folder that are not referenced anywhere in the Markdown files. It helps clean up unused image files to reduce repository size.
Supported Image Reference Formats
The script recognizes images referenced in the following ways:
- Standard Markdown:
 - HTML:
<img src="path/to/image.png" alt="alt text"> - Obsidian-style:
![[image.png]]
Usage
Prerequisites
- Deno installed on your system.
Running the Script
deno run --allow-read index.ts [markdown_folder] [images_folder]Parameters
markdown_folder(optional): Path to the folder containing Markdown files. Default:../(relative to the script location, typicallycontent/).images_folder(optional): Path to the folder containing images. Default:../images(relative to the script location, typicallycontent/images/).
Examples
-
Run with defaults:
deno run --allow-read index.ts -
Specify custom paths:
deno run --allow-read index.ts /path/to/markdown /path/to/images
Output
The script outputs:
- A list of unused image filenames.
- Suggested
rmcommands to remove the unused images.
If no unused images are found, it displays “No unused images found.”
How It Works
- Scans the specified Markdown folder for
.mdfiles. - Extracts image filenames from supported reference formats.
- Lists all files in the images folder.
- Compares the lists to find unreferenced images.
- Outputs the results.
Notes
- Paths are resolved relative to the script’s location if defaults are used.
- Only filenames are compared (not full paths), assuming relative references.
- The script requires read access to the folders, hence the
--allow-readflag.