Post Date And Snippet Validation Design
Goal
Add two repository checks that work both locally and in CI:
- A post filename date in
_posts/YYYY-MM-DD-slug.md must match the calendar day in its front matter date.
- A future-dated post must have a matching companion snippet in
_snippets/. Locally, missing or stale snippets should be generated or refreshed before commit. In CI, validation should fail instead of mutating files.
Approach
Use one shared Python validation script and one shared Python snippet generator.
scripts/validate_posts.py
- Parses
_posts/*.md
- Verifies filename date matches front matter date
- Verifies future-dated posts have matching snippets
- Verifies snippet metadata stays aligned with the post
- Supports
--staged for hook use
- Supports
--today YYYY-MM-DD for deterministic checks
scripts/generate_social_snippets.py
- Reads a post from
_posts/
- Derives title, slug, canonical URL, and basic metadata
- Generates the standard snippet scaffold and distinct platform copy
- Writes or refreshes
_snippets/<same filename>.md
Local Hook Flow
scripts/install_git_hooks.sh installs repo-managed pre-commit and pre-push hooks into .git/hooks/
pre-commit
- finds staged posts
- for future-dated staged posts, generates or refreshes snippets
- stages those snippet updates
- runs
validate_posts.py --staged
pre-push
- runs
validate_posts.py across the repo
CI Flow
Add .github/workflows/validate_posts.yml
- run the validator in check-only mode
- fail the workflow if dates mismatch or future snippets are missing or stale
Notes
- “Future-dated” means the post date is later than the current calendar day in the site timezone.
- Date validation compares only the calendar day, not the exact publish time.
- Local hooks may mutate files. CI must not.