From d58827d5fc32fd4fbd70a9f9413d657ae9a8c6a1 Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Thu, 29 May 2025 17:55:42 -0400 Subject: [PATCH] initial commit --- README.md | 1 + hugotags.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 README.md create mode 100755 hugotags.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..8aa0005 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +## Hugo tags generator diff --git a/hugotags.sh b/hugotags.sh new file mode 100755 index 0000000..9c4fe10 --- /dev/null +++ b/hugotags.sh @@ -0,0 +1,58 @@ +#!/usr/bin/bash + +set -euo pipefail + +# Dependency: https://mikefarah.gitbook.io/yq/ + +# Clone from https://github.com/gohugoio/hugoDocs/ and checkout the tag of your +# hugo version +# Path to /content/en/ +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 + if [ "$(basename "$f")" = _index.md ]; then + continue + fi + + title="$(yq --front-matter extract .title "$f")" + add_tag "$title" "$f" + + done +} + +add_funcs() { + local f halias + + for f in functions/*/*md; do + if [ "$(basename "$f")" = _index.md ]; then + continue + fi + + add_tag "$(basename "${f%.md}")" "$f" + + halias="$(yq --front-matter extract .params.functions_and_methods.aliases "$f" | + grep -v -F -e null -e '[]' -e ',')" # Remove invalid/missing/multiple aliases + + if [ -n "$halias" ]; then + halias="${halias:1:${#halias}-2}" + add_tag "$halias" "$f" + fi + done +} + +add_methods +add_funcs