|
| 1 | +#!/usr/bin/env bash |
| 2 | +# validate.sh — checks collection integrity for awesome-design-md |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 6 | +DESIGN_DIR="$REPO_ROOT/design-md" |
| 7 | +README="$REPO_ROOT/README.md" |
| 8 | + |
| 9 | +errors=0 |
| 10 | +warnings=0 |
| 11 | + |
| 12 | +red() { printf '\033[31m%s\033[0m\n' "$*"; } |
| 13 | +yellow() { printf '\033[33m%s\033[0m\n' "$*"; } |
| 14 | +green() { printf '\033[32m%s\033[0m\n' "$*"; } |
| 15 | + |
| 16 | +# ── 1. Check design-md directory exists ─────────────────────────────────────── |
| 17 | +if [[ ! -d "$DESIGN_DIR" ]]; then |
| 18 | + red "ERROR: design-md/ directory not found" |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +# ── 2. Entry completeness ───────────────────────────────────────────────────── |
| 23 | +echo "Checking entry completeness..." |
| 24 | +while IFS= read -r -d '' dir; do |
| 25 | + site=$(basename "$dir") |
| 26 | + for required in DESIGN.md preview.html preview-dark.html; do |
| 27 | + if [[ ! -f "$dir/$required" ]]; then |
| 28 | + red " MISSING: design-md/$site/$required" |
| 29 | + ((errors++)) || true |
| 30 | + fi |
| 31 | + done |
| 32 | +done < <(find "$DESIGN_DIR" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z) |
| 33 | + |
| 34 | +# ── 3. DESIGN.md schema — all 9 sections present ────────────────────────────── |
| 35 | +echo "Checking DESIGN.md section schema..." |
| 36 | +while IFS= read -r -d '' file; do |
| 37 | + site=$(basename "$(dirname "$file")") |
| 38 | + for i in $(seq 1 9); do |
| 39 | + if ! grep -q "^## $i\." "$file" 2>/dev/null; then |
| 40 | + red " MISSING section ## $i. in design-md/$site/DESIGN.md" |
| 41 | + ((errors++)) || true |
| 42 | + fi |
| 43 | + done |
| 44 | +done < <(find "$DESIGN_DIR" -name "DESIGN.md" -print0 | sort -z) |
| 45 | + |
| 46 | +# ── 4. README badge count vs actual entry count ─────────────────────────────── |
| 47 | +echo "Checking README badge count..." |
| 48 | +actual_count=$(find "$DESIGN_DIR" -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ') |
| 49 | +badge_count=$(grep -oP 'DESIGN\.md%20count-\K[0-9]+' "$README" || echo "0") |
| 50 | + |
| 51 | +if [[ "$badge_count" != "$actual_count" ]]; then |
| 52 | + red " MISMATCH: README badge shows $badge_count but $actual_count directories exist" |
| 53 | + ((errors++)) || true |
| 54 | +else |
| 55 | + green " Badge count OK: $actual_count" |
| 56 | +fi |
| 57 | + |
| 58 | +# ── 5. README collection index vs directories ───────────────────────────────── |
| 59 | +echo "Checking README index sync..." |
| 60 | +while IFS= read -r -d '' dir; do |
| 61 | + site=$(basename "$dir") |
| 62 | + if ! grep -q "design-md/$site/" "$README"; then |
| 63 | + yellow " WARNING: design-md/$site/ not listed in README" |
| 64 | + ((warnings++)) || true |
| 65 | + fi |
| 66 | +done < <(find "$DESIGN_DIR" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z) |
| 67 | + |
| 68 | +# ── 6. Preview HTML structure ───────────────────────────────────────────────── |
| 69 | +echo "Checking preview HTML structure..." |
| 70 | +for html_file in preview.html preview-dark.html; do |
| 71 | + while IFS= read -r -d '' file; do |
| 72 | + site=$(basename "$(dirname "$file")") |
| 73 | + if ! grep -qi "<!DOCTYPE" "$file"; then |
| 74 | + yellow " WARNING: missing DOCTYPE in design-md/$site/$html_file" |
| 75 | + ((warnings++)) || true |
| 76 | + fi |
| 77 | + if ! grep -qi 'charset' "$file"; then |
| 78 | + yellow " WARNING: missing charset in design-md/$site/$html_file" |
| 79 | + ((warnings++)) || true |
| 80 | + fi |
| 81 | + if ! grep -qi 'viewport' "$file"; then |
| 82 | + yellow " WARNING: missing viewport in design-md/$site/$html_file" |
| 83 | + ((warnings++)) || true |
| 84 | + fi |
| 85 | + done < <(find "$DESIGN_DIR" -name "$html_file" -print0 | sort -z) |
| 86 | +done |
| 87 | + |
| 88 | +# ── Summary ─────────────────────────────────────────────────────────────────── |
| 89 | +echo "" |
| 90 | +if [[ $errors -gt 0 ]]; then |
| 91 | + red "Validation failed: $errors error(s), $warnings warning(s)" |
| 92 | + exit 1 |
| 93 | +else |
| 94 | + green "Validation passed: 0 errors, $warnings warning(s)" |
| 95 | +fi |
0 commit comments