~kris/dots

srice

ref: 9f828eb14bdd54d2c4fd8a3b2c90253021df3152 srice/.local/bin/blog-frontmatter -rwxr-xr-x 789 bytes
9f828eb1 — Kris Yotam mksh: backslash-escape commands in history hook to bypass module aliases (wc=tokei, tr=transmission-remote, cat=bat) 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
30
31
32
33
34
#!/usr/bin/env sh
set -eu

status=0
fields=${BLOG_REQUIRED_FIELDS:-title date}
tmp=${TMPDIR:-.}/blog-frontmatter.$$
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
  first=$(sed -n '1p' "$f")
  if [ "$first" != "---" ]; then
    printf 'missing frontmatter: %s\n' "$f"
    status=1
    continue
  fi
  for field in $fields; do
    if ! sed -n '1,/^---$/p' "$f" | rg -q "^$field:"; then
      printf 'missing %s: %s\n' "$field" "$f"
      status=1
    fi
  done
done < "$tmp"

exit "$status"