~kris/dots

srice

ref: e9b48d06a8541f3eda5c4db90382ab3c77183afb srice/.local/bin/blog-future-dates -rwxr-xr-x 838 bytes
e9b48d06 — Kris Yotam xprofile: systemd-aware pipewire start + blueman-applet; sb-internet: tolerate missing /proc/net/wireless 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/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"