diff options
Diffstat (limited to 'js/src/doc/lib/common.sh')
-rw-r--r-- | js/src/doc/lib/common.sh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/js/src/doc/lib/common.sh b/js/src/doc/lib/common.sh new file mode 100644 index 000000000..785f7dec1 --- /dev/null +++ b/js/src/doc/lib/common.sh @@ -0,0 +1,23 @@ +# Common utility functions for js/src/doc scripts. + +# `relative BASE ABSOLUTE` prints the URL relative to BASE that is +# equivalent to ABSOLUTE. BASE must end with a '/'. This function will +# introduce at most one level of '..'. +relative() { + local parent=$(dirname "$1") + case "$2" in + "$1"*) + # ABSOLUTE is within BASE; just remove BASE. + echo "$2" | sed -e "s|^$1||" + ;; + "$parent/"*) + # ABSOLUTE is within BASE/.. + echo "$2" | sed -e "s|^$parent/|../|" + ;; + *) + # ABSOLUTE is unrelated to BASE. + echo "$2" + ;; + esac +} + |