~kris/dots

srice

ref: e98f3b030dc24445bd55c68d95d2d81933fd68b3 srice/.local/bin/blog-backlinks -rw-r--r-- 653 bytes
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env sh
set -eu

tmp=${TMPDIR:-.}/blog-backlinks.$$
trap 'rm -f "$tmp"' EXIT HUP INT TERM

find . \( -path '*/.git' -o -path '*/node_modules' -o -path '*/.next' -o -path '*/_site' \) -prune -o -type f \( -name '*.md' -o -name '*.mdx' -o -name '*.org' \) -print > "$tmp"

while IFS= read -r target; do
  slug=$(basename "$target" | sed -e 's/\.[^.]*$//' -e 's/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-//')
  [ -n "$slug" ] || continue
  hits=$(xargs -r rg -l --fixed-strings "$slug" < "$tmp" | grep -Fv -- "$target" || true)
  [ -n "$hits" ] || continue
  printf '## %s\n\n' "$target"
  printf '%s\n\n' "$hits" | sed 's/^/- /'
done < "$tmp"