aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin/coll2path
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xv2/src/bin/coll2path88
1 files changed, 88 insertions, 0 deletions
diff --git a/v2/src/bin/coll2path b/v2/src/bin/coll2path
new file mode 100755
index 0000000..79b2f53
--- /dev/null
+++ b/v2/src/bin/coll2path
@@ -0,0 +1,88 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ coll2path LANGUAGE COLLECTION
+ coll2path -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+
+ Options:
+ -h, --help show this message
+
+ LANGUAGE in which language to list the collections
+ names for
+ COLLECTION what collection to get the path for
+
+
+ Get the path for the COLLECTION, doing the proper translation
+ on the way, and checking if is "article".
+
+
+ Examples:
+
+ Get the path for "TIL" in portuguese:
+
+ $ coll2path pt til
+ hea/
+
+
+ Get the path for "articles" in english
+
+ $ collections en articles
+
+ EOF
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ esac
+done
+shift $((OPTIND - 1))
+
+. src/lib.sh
+
+
+LANGUAGE="${1:-}"
+COLLECTION="${2:-}"
+eval "$(assert_arg "$LANGUAGE" 'LANGUAGE')"
+
+# shellcheck source=/dev/null
+. src/lib/commencement."$LANGUAGE".conf
+
+if [ -z "$COLLECTION" ]; then
+ echo "${article_collection_name:-}"
+else
+ NAME="$(eval "echo \"\$${COLLECTION}_collection_name\"")"
+ echo "$NAME${NAME:+/}"
+fi