diff options
author | EuAndreh <eu@euandre.org> | 2023-04-09 18:59:09 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-04-09 19:05:39 -0300 |
commit | 19a8b995c59cce5315e1d121054f9c27aad5c960 (patch) | |
tree | f2c2d83751245004beed21b31d973c1d412cd026 /v2/src/bin/url-for | |
parent | v2: CSS dark mode, including SVGs (diff) | |
download | euandre.org-19a8b995c59cce5315e1d121054f9c27aad5c960.tar.gz euandre.org-19a8b995c59cce5315e1d121054f9c27aad5c960.tar.xz |
v2: Support translated alternates in <nav>
Diffstat (limited to 'v2/src/bin/url-for')
-rwxr-xr-x | v2/src/bin/url-for | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/v2/src/bin/url-for b/v2/src/bin/url-for index a1b4d1a..e0b1c9d 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 [CONTENT...] url-for -h EOF } @@ -15,11 +15,11 @@ help() { Options: -h, --help show this message - FILE the path for the URL to be constructed + CONTENT literal strings to be transformed into URLs - Build an URL for the given FILE, without the $domain part, adding - the required $base_url. + Build an URL without the $domain part, adding the required + $base_url. If CONTENT is not given, get data from STDIN. Examples: @@ -32,7 +32,7 @@ help() { Get the URL for "static/favicon.svg", when $base_url is empty: - $ url-for 'img/link.svg' + $ echo 'img/link.svg' | url-for /img/link.svg EOF } @@ -68,17 +68,26 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) -. src/lib.sh - -FILE="${1:-}" -eval "$(assert_arg "$FILE" 'FILE')" - - -if [ "$FILE" = '/' ]; then - FILE='' -fi . src/lib/base.conf -printf '%s%s' "${base_url:-/}" "$FILE" +url() { + sed \ + -e "s|^$CONTENT_PREFIX/||" \ + -e 's|\.md|.html|' \ + -e 's|\.page|.html|' \ + -e 's|^/||' | + printf '%s%s\n' "${base_url:-/}" "$(cat -)" +} + +if [ $# = 0 ]; then + url +else + for f in "$@"; do + if [ "$f" = '/' ]; then + f='' + fi + printf '%s\n' "$f" | url + done +fi |