revamp projects, continue editing and add precommit hook for lastmod frontmatter
This commit is contained in:
@@ -5,6 +5,12 @@ NC='\033[0m' # No Color
|
||||
|
||||
echo "Running pre-commit checks..."
|
||||
|
||||
# Auto-update lastmod in content files (non-blocking)
|
||||
# Runs before other checks so lint/spell run on updated files
|
||||
if [ -x "$(dirname "$0")/update-lastmod.sh" ]; then
|
||||
"$(dirname "$0")/update-lastmod.sh" || echo "⚠️ lastmod update script encountered an issue"
|
||||
fi
|
||||
|
||||
# Track overall success/failure
|
||||
OVERALL_RESULT=0
|
||||
|
||||
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# Auto-update lastmod field in staged content files
|
||||
# This script should never block a commit - errors are warnings only
|
||||
|
||||
update_lastmod() {
|
||||
local file="$1"
|
||||
|
||||
# Generate RFC3339 timestamp with timezone (e.g., 2025-11-08T16:19:07-06:00)
|
||||
local tz_offset=$(date +%z)
|
||||
local tz_formatted="${tz_offset:0:3}:${tz_offset:3:2}" # Insert colon: -0600 -> -06:00
|
||||
local now=$(date +%Y-%m-%dT%H:%M:%S)${tz_formatted}
|
||||
|
||||
# Only update if file has lastmod field
|
||||
if grep -q "^lastmod:" "$file"; then
|
||||
# Cross-platform sed -i (macOS vs Linux)
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
sed -i '' "s/^lastmod:.*$/lastmod: $now/" "$file"
|
||||
else
|
||||
sed -i "s/^lastmod:.*$/lastmod: $now/" "$file"
|
||||
fi
|
||||
git add "$file"
|
||||
echo " Updated lastmod in $file"
|
||||
fi
|
||||
}
|
||||
|
||||
# Get staged content files
|
||||
staged_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^content/.*\.md$' || true)
|
||||
|
||||
if [ -z "$staged_files" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for file in $staged_files; do
|
||||
if [ -f "$file" ]; then
|
||||
update_lastmod "$file" || echo "Warning: Failed to update lastmod in $file"
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user