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: ![alt text](path/to/image.png)
  • 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, typically content/).
  • images_folder (optional): Path to the folder containing images. Default: ../images (relative to the script location, typically content/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 rm commands to remove the unused images.

If no unused images are found, it displays “No unused images found.”

How It Works

  1. Scans the specified Markdown folder for .md files.
  2. Extracts image filenames from supported reference formats.
  3. Lists all files in the images folder.
  4. Compares the lists to find unreferenced images.
  5. 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-read flag.