Add broken-image pre-commit hook for internal refs (closes #34)#39
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #34.
Summary
Adds a
localpre-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 inpeople.html)(Markdown image syntax)Then filtered to paths ending in
.png|.jpg|.jpeg|.gif|.svg|.webp|.ico|.bmp.Skipped:
http://,https://,//,data:,mailto:){{ ... }}or{% ... %})_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.ymlworkflow.Test plan
pre-commit run image-refs --all-filespasses on the current repo (no false positives across*.html,*.md,_posts/,_layouts/,_includes/)and<img src="/images/also-missing.png">is rejected with file:line:url outputpre-commitandsite-healthjobs passNotes
_site/blogexclude tracked in Clean up legacy blog post link rot (~30 dead links across 2015-2018 posts) #36).https://claude.ai/code/session_01S5QXfkxZBNSAf2Y1XAD8H7
Generated by Claude Code