aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xv2/src/bin/url-for39
1 files changed, 27 insertions, 12 deletions
diff --git a/v2/src/bin/url-for b/v2/src/bin/url-for
index c31ff84..d4099bc 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 FILE
+ url-for [-g] FILE
url-for -h
EOF
}
@@ -13,27 +13,28 @@ 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
- Build an URL for the given FILE, without the FQDN part, adding
- the required BASE_URL.
+ Build an URL for the given FILE, without the $domain part, adding
+ the required $base_url.
Examples:
- Get the URL for "static/style.css", when BASE_URL is empty:
+ Get the URL for "about.html", when $base_url is "v2" and $lang is "en":
- $ url-for 'static/style.css'
- /static/style.css
+ $ url-for 'about.html'
+ /v2/en/about.html
- Get the URL for "static/favicon.svg", when BASE_URL is "v2":
+ Get the URL for "static/favicon.svg", when $base_url is empty:
- $ url-for 'static/favicon.svg'
- /v2/static/favicon.svg
+ $ url-for -g 'static/favicon.svg'
+ /static/favicon.svg
EOF
}
@@ -53,8 +54,12 @@ for flag in "$@"; do
esac
done
-while getopts 'h' flag; do
+GLOBAL=false
+while getopts 'gh' flag; do
case "$flag" in
+ g)
+ GLOBAL=true
+ ;;
h)
usage
help
@@ -72,8 +77,18 @@ shift $((OPTIND - 1))
FILE="${1:-}"
-eval "$(assert_arg "$FILE" 'FILE')"
+if [ "$FILE" = '/' ]; then
+ FILE=''
+fi
. 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' "${base_url:-/}" "$FILE"
+printf '%s%s%s' "${base_url:-/}" "$L" "$FILE"