#!/usr/bin/env bash tag="$(echo "$1" | tr ' ' '_' | tr 'A-Z' 'a-z')" if [ "$tag" == "all" ]; then find content/blog/ -type f -name '*.md' -not -name 'xxx-*' | sort -r -u | cut -d '-' -f 2- | cut -d '.' -f 1 else find content/blog/ -type f -name '*.md' -not -name 'xxx-*' | sort -r -u | while read file; do tags="$(sed -n '/---/,/---/p' "$file" | sed -n '1,/---/p' | sed '/^---$/d' | sed '/^$/,$d' | yq -r 'if ( .tags | type ) == "array" then .tags else [ .tags ] end | join("\n")' | tr 'A-Z' 'a-z' | tr ' ' '_' )" if echo "$tags" | grep -q "$tag"; then echo "$file" | cut -d '-' -f 2- | cut -d '.' -f 1 fi done fi