createdが今日の日付になっているノートを集計する方法

yq を使用してfrontmatterを取得する。

#!/usr/bin/env bash
set -eu
 
usage() {
  echo "usage: $0 [YYYY-MM-DD | [+/-N]]" >&2
  exit 1
}
 
arg="${1-}"
 
if [ -z "$arg" ]; then
  TARGET_DATE="$(date +%F)"
elif [[ "$arg" =~ ^[+-][0-9]+$ ]]; then
  TARGET_DATE="$(date -d "$arg day" +%F)"
elif [[ "$arg" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
  TARGET_DATE="$arg"
else
  usage
fi
 
echo "TARGET_DATE=$TARGET_DATE" >&2
 
find . -name '*.md' -print0 |
  while IFS= read -r -d '' f; do
    # 先頭行が --- でないファイルは frontmatter なしとしてスキップ
    if [ "$(head -n1 "$f" || true)" != "---" ]; then
      continue
    fi
 
    # created が "YYYY-MM-DD" または "YYYY-MM-DD HH:MM" 等を想定
    if yq --front-matter=extract \
         '(.created | tostring | split(" ")[0]) == "'"$TARGET_DATE"'"' "$f" \
        2>/dev/null | grep -q '^true$'; then
      printf '%s'"$f\n"
    fi
  done

yq --front-matter=extract のあとに取得したいキーを書くことでjq のように要素を取り出せる。