hugotags/hugotags.sh

47 lines
743 B
Bash
Executable File

#!/usr/bin/bash
set -euo pipefail
hugo_docs_path="$1"
cd "$hugo_docs_path"
add_tag() {
local tagname fname
tagname="$1"
fname="$2"
# Tags file format: https://vimhelp.org/tagsrch.txt.html#ctags
printf "%s\t%s\t2\n" "$tagname" "$hugo_docs_path/$fname"
}
add_methods() {
local f title
for f in methods/*/*md; do
title="$(yq --front-matter extract .title "$f")"
add_tag "$title" "$f"
done
}
add_funcs() {
local f halias
for f in functions/*/*md; do
add_tag "$(basename "${f%.md}")" "$f"
halias="$(yq --front-matter extract .params.functions_and_methods.aliases[0] "$f")"
if [ "$halias" != "null" ]; then
add_tag "$halias" "$f"
fi
done
}
{
add_methods
add_funcs
} | grep -v _index.md | sort --ignore-case