- README.md: Proper forge-log introduction with structure docs - entries/2026-04-04.md: First forge log entry — the awakening - templates/daily_entry.md: Template for daily entries - scripts/validate_entry.sh: YAML frontmatter validator #bezalel-artisan
84 lines
2.3 KiB
Bash
Executable File
84 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# validate_entry.sh — Validate a forge-log entry has proper YAML frontmatter
|
|
# Usage: ./scripts/validate_entry.sh <entry_file>
|
|
|
|
set -euo pipefail
|
|
|
|
if [ $# -eq 0 ]; then
|
|
echo "Usage: $0 <entry_file> [entry_file2 ...]"
|
|
echo "Example: $0 entries/2026-04-04.md"
|
|
exit 1
|
|
fi
|
|
|
|
errors=0
|
|
checked=0
|
|
|
|
for file in "$@"; do
|
|
checked=$((checked + 1))
|
|
file_errors=0
|
|
|
|
if [ ! -f "$file" ]; then
|
|
echo "FAIL: $file — file not found"
|
|
errors=$((errors + 1))
|
|
continue
|
|
fi
|
|
|
|
# Check file starts with ---
|
|
first_line=$(head -1 "$file")
|
|
if [ "$first_line" != "---" ]; then
|
|
echo "FAIL: $file — missing opening '---' frontmatter delimiter"
|
|
file_errors=$((file_errors + 1))
|
|
fi
|
|
|
|
# Find closing --- (second occurrence)
|
|
closing_line=$(awk 'NR>1 && /^---$/ {print NR; exit}' "$file")
|
|
if [ -z "$closing_line" ]; then
|
|
echo "FAIL: $file — missing closing '---' frontmatter delimiter"
|
|
file_errors=$((file_errors + 1))
|
|
fi
|
|
|
|
# Check required fields in frontmatter
|
|
if [ -n "$closing_line" ]; then
|
|
frontmatter=$(sed -n "2,$((closing_line - 1))p" "$file")
|
|
|
|
# Check for date field
|
|
if ! echo "$frontmatter" | grep -q "^date:"; then
|
|
echo "FAIL: $file — missing 'date' field in frontmatter"
|
|
file_errors=$((file_errors + 1))
|
|
fi
|
|
|
|
# Check for wizard field
|
|
if ! echo "$frontmatter" | grep -q "^wizard:"; then
|
|
echo "FAIL: $file — missing 'wizard' field in frontmatter"
|
|
file_errors=$((file_errors + 1))
|
|
fi
|
|
|
|
# Check for tags field
|
|
if ! echo "$frontmatter" | grep -q "^tags:"; then
|
|
echo "FAIL: $file — missing 'tags' field in frontmatter"
|
|
file_errors=$((file_errors + 1))
|
|
fi
|
|
|
|
# Check for status field
|
|
if ! echo "$frontmatter" | grep -q "^status:"; then
|
|
echo "FAIL: $file — missing 'status' field in frontmatter"
|
|
file_errors=$((file_errors + 1))
|
|
fi
|
|
fi
|
|
|
|
if [ "$file_errors" -eq 0 ]; then
|
|
echo "PASS: $file — valid frontmatter (date, wizard, tags, status)"
|
|
else
|
|
errors=$((errors + file_errors))
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "Checked: $checked file(s), Errors: $errors"
|
|
|
|
if [ "$errors" -gt 0 ]; then
|
|
exit 1
|
|
fi
|
|
|
|
exit 0
|