feat(docs): Makefile commands for doc image cleanup + remove unused images + workflow warnings on doc images #1
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
| name: Docs Image Check | |
| on: | |
| pull_request: | |
| paths: | |
| - "docs/**" | |
| jobs: | |
| docs-images: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Check for unused images (warn only) | |
| run: | | |
| cd docs | |
| unused=0 | |
| find . -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.gif" -o -iname "*.svg" \) -print0 | \ | |
| while IFS= read -r -d '' img; do | |
| img_name=$(basename "$img") | |
| img_path=${img#./} | |
| if ! grep -r --include="*.md" --include="*.mdx" --include="*.json" -e "$img_name" -e "$img_path" . > /dev/null; then | |
| echo "⚠️ Unused image found: $img" | |
| unused=1 | |
| fi | |
| done | |
| if [ "$unused" -eq 1 ]; then | |
| echo "" | |
| echo "⚠️ Some unused images were found." | |
| echo "👉 Run 'make clean-docs-images' locally to remove them." | |
| fi | |
| - name: Verify referenced images exist (fail on missing) | |
| run: | | |
| cd docs | |
| missing=0 | |
| find . -type f \( -iname "*.md" -o -iname "*.mdx" -o -iname "*.json" \) -print0 | \ | |
| xargs -0 -I{} grep -o -E "\([^()\"']*\.(png|jpg|jpeg|gif|svg)[^()\"']*\)" {} 2>/dev/null | \ | |
| sort -u | while read -r img_ref; do | |
| img_ref=$(echo "$img_ref" | sed 's/^(\(.*\))$/\1/') | |
| if [[ "$img_ref" == /* ]]; then | |
| real_path="./$img_ref" | |
| else | |
| real_path=$(echo "$img_ref" | sed 's|\(\.\./\)*|./|') | |
| fi | |
| if [ ! -f "$real_path" ]; then | |
| echo "❌ Missing image: $img_ref" | |
| missing=1 | |
| fi | |
| done | |
| if [ "$missing" -eq 1 ]; then | |
| echo "" | |
| echo "❌ Some referenced images are missing!" | |
| exit 1 | |
| fi |