diff options
Diffstat (limited to 'v2/src/bin/url-for')
-rwxr-xr-x | v2/src/bin/url-for | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/v2/src/bin/url-for b/v2/src/bin/url-for index d4099bc..adaccd7 100755 --- a/v2/src/bin/url-for +++ b/v2/src/bin/url-for @@ -4,7 +4,7 @@ set -eu usage() { cat <<-'EOF' Usage: - url-for [-g] FILE + url-for FILE url-for -h EOF } @@ -13,7 +13,6 @@ help() { cat <<-'EOF' Options: - -g global file, not specific to a single language -h, --help show this message FILE the path for the URL to be constructed @@ -25,7 +24,7 @@ help() { Examples: - Get the URL for "about.html", when $base_url is "v2" and $lang is "en": + Get the URL for "en/about.html", when $base_url is "v2": $ url-for 'about.html' /v2/en/about.html @@ -33,8 +32,8 @@ help() { Get the URL for "static/favicon.svg", when $base_url is empty: - $ url-for -g 'static/favicon.svg' - /static/favicon.svg + $ url-for 'img/link.svg' + /img/link.svg EOF } @@ -54,12 +53,8 @@ for flag in "$@"; do esac done -GLOBAL=false -while getopts 'gh' flag; do +while getopts 'h' flag; do case "$flag" in - g) - GLOBAL=true - ;; h) usage help @@ -73,22 +68,19 @@ while getopts 'gh' flag; do done shift $((OPTIND - 1)) -. src/development/lib.sh - +. src/lib.sh FILE="${1:-}" +eval "$(assert_arg "$FILE" 'FILE')" + + if [ "$FILE" = '/' ]; then FILE='' fi -. src/lib/base-conf +. src/lib/base.conf # shellcheck source=/dev/null . src/lib/base."${lang:?}".conf -if [ "$GLOBAL" = true ]; then - L='' -else - L="${lang:?}/" -fi -printf '%s%s%s' "${base_url:-/}" "$L" "$FILE" +printf '%s%s' "${base_url:-/}" "$FILE" |