putnam hill moments a place for my stuff

get-tags

a bash script that lists slugified tags found in front matter tags array
#!/usr/bin/env bash

usage() {
cat <<EOT
list tags in front matter tags array as slugified strings
usage: ${0##*/} _posts/p1.md [_posts/p2.md] ...
	-h display this message
EOT
}

print_tags() {
	local post="$1"

	sed -nf 'collections/_bin/_front-matter.sed' "$post" | \
	yq '.tags[]' | \
	sed -f 'collections/_bin/_slugify.sed'
}

die() {
	local err="$1"
	shift
	test -n "$*" && echo "$*" >&2
	exit $err
}

# the following will help allow access to the sed scripts
test "$(git rev-parse --show-toplevel)" == "$PWD" || \
	die 1 "please run ${0##*/} from the top level of the repository"

# parse the command-line options:
while getopts 'h' option; do
	case "$option" in
		h) usage; exit 0 ;;
		?) usage; exit 0 ;;
	esac
done
(( OPTIND-- ))
shift $OPTIND

if [ $# -gt 0 ]; then  # process remaining args on the commandline
	while [ $# -gt 0 ]; do
		print_tags "$1"
		shift
	done
else usage; fi