Skip to content

Add broken-image pre-commit hook for internal refs (closes #34)#39

Merged
jmxpearson merged 1 commit into
masterfrom
claude/issue-34-broken-image-checker
May 11, 2026
Merged

Add broken-image pre-commit hook for internal refs (closes #34)#39
jmxpearson merged 1 commit into
masterfrom
claude/issue-34-broken-image-checker

Conversation

@jmxpearson

Copy link
Copy Markdown
Member

Closes #34.

Summary

Adds a local pre-commit hook (scripts/check_image_refs.py) that scans staged HTML and Markdown files for image references and fails the commit if a root-relative path doesn't exist in the repo. Pairs with the dibs-web01 migration (#33) — same failure mode (image src points at something that isn't there), now caught at commit time.

Patterns matched:

  • src="..." (HTML <img> and similar)
  • image="..." (Jekyll include parameter used in people.html)
  • ![alt](...) (Markdown image syntax)

Then filtered to paths ending in .png|.jpg|.jpeg|.gif|.svg|.webp|.ico|.bmp.

Skipped:

  • External URLs (http://, https://, //, data:, mailto:)
  • Liquid-templated paths (anything containing {{ ... }} or {% ... %})
  • Non-leading-slash relative paths (ambiguous under Jekyll URL rewriting; lychee catches those in CI via the built _site/)

Why pre-commit + internal-only

External URL checking would make commits depend on network and slow them down. Lychee already covers external refs in site-health.yml, so the value-add of the pre-commit hook is the internal case: catching typos and orphaned refs at commit time rather than after deploy.

CI inherits the new hook automatically via the existing pre-commit.yml workflow.

Test plan

  • pre-commit run image-refs --all-files passes on the current repo (no false positives across *.html, *.md, _posts/, _layouts/, _includes/)
  • Synthetic test: a file with ![](/images/this-does-not-exist.jpg) and <img src="/images/also-missing.png"> is rejected with file:line:url output
  • External URLs and Liquid-templated paths are correctly skipped
  • CI pre-commit and site-health jobs pass

Notes

https://claude.ai/code/session_01S5QXfkxZBNSAf2Y1XAD8H7


Generated by Claude Code

Scans staged HTML/Markdown for image references (src=, image=, and
Markdown ![]()), and fails the commit if a root-relative path doesn't
exist in the repo. Catches typos and the dibs-web01-style failure
mode where a referenced image goes missing.

Scope is internal refs only — external URLs and Liquid-templated paths
are skipped. Lychee in site-health CI already covers external links,
and pre-commit shouldn't make commits depend on network. CI gets the
new hook automatically via the existing pre-commit workflow.

Stdlib-only Python (no new dependencies).
@jmxpearson jmxpearson merged commit b0c085b into master May 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add broken-image pre-commit hook + CI check

2 participants