#!/usr/bin/env sh set -eu today=$(date -u +%F) allow=${BLOG_ALLOW_FUTURE_DATES:-} status=0 tmp=${TMPDIR:-.}/blog-future-dates.$$ trap 'rm -f "$tmp"' EXIT HUP INT TERM if [ "$#" -gt 0 ]; then printf '%s\n' "$@" > "$tmp" else : > "$tmp" for d in content posts post blog notes garden essays articles src/content src/pages _posts pages; do [ -d "$d" ] || continue find "$d" -type f \( -name '*.md' -o -name '*.mdx' \) >> "$tmp" done fi while IFS= read -r f; do date_value=$(sed -n '1,/^---$/s/^\(date\|published\|start_date\):[[:space:]]*["'\'']*\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\).*/\2/p' "$f" | sed -n '1p') [ -n "$date_value" ] || continue if [ "$date_value" \> "$today" ] && [ "$allow" != "1" ]; then printf 'future date: %s %s\n' "$date_value" "$f" status=1 fi done < "$tmp" exit "$status"