diff options
Diffstat (limited to '')
-rwxr-xr-x | v2/src/bin/absolute | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/v2/src/bin/absolute b/v2/src/bin/absolute index ecf5a64..f475901 100755 --- a/v2/src/bin/absolute +++ b/v2/src/bin/absolute @@ -5,7 +5,7 @@ set -eu usage() { cat <<-'EOF' Usage: - absolute < STDIN + absolute [CONTENT...] absolute -h EOF } @@ -16,9 +16,13 @@ help() { Options: -h, --help show this message + CONTENT a literal string to be prefixed - Read URL from STDIN and adds the FQDN prefix. Meant to be used - in conjunction with `url-for`. + + Add domain prefix to build a full URL. If CONTENT is not given, + get data from STDIN. + + Usually used in conjunction with url-for(1). Examples: @@ -27,6 +31,12 @@ help() { $ url-for 'static/style.css' | absolute https://euandre.org/static/style.css + + + Get the absolute variant of a relative URL: + + $ absolute "$homepage_url" + https://euandre.org/pt/ EOF } @@ -64,4 +74,16 @@ shift $((OPTIND - 1)) . src/lib/base.conf -printf 'https://%s%s' "$domain" "$(cat)" + +prefix() { + sed "s|^/\?|https://$domain/|" +} + + +if [ $# = 0 ]; then + prefix +else + for s in "$@"; do + printf '%s\n' "$s" | prefix + done +fi |