putnam hill moments a place for my stuff

gen-tags

a bash script that creates tag files
#!/usr/bin/env bash

usage() {
cat <<EOT
create jekyll tag pages
usage: ${0##*/} tag1 [tag2] ...
	-h display this message
EOT
}

gen_tag_page() {
	local tag="$1"

	echo "creating tag page $tag" >&2
	cat <<EOT > "collections/_tag/$tag.md"
---
title: $tag
---
EOT
	git add "collections/_tag/$tag.md"
}

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

# the following will help create tag pages in the right place
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
		gen_tag_page "$1"
		shift
	done
else usage; fi