aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin/url-for
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-04-09 18:59:09 -0300
committerEuAndreh <eu@euandre.org>2023-04-09 19:05:39 -0300
commit19a8b995c59cce5315e1d121054f9c27aad5c960 (patch)
treef2c2d83751245004beed21b31d973c1d412cd026 /v2/src/bin/url-for
parentv2: CSS dark mode, including SVGs (diff)
downloadeuandre.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-xv2/src/bin/url-for39
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