X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=processor%2Fhelpers.sh;h=2869a29a3d414db7066c71e17ff1439b0b7c6c92;hb=26fed190fe4fbdb96a33cc180297b597c9c1e38b;hp=cc12358cdd1618c3b6c27f0fdbe2a1b26091af72;hpb=4373137de8ac6ad8731e6828a9876de9efe0a82e;p=redo-blog
diff --git a/processor/helpers.sh b/processor/helpers.sh
index cc12358..2869a29 100644
--- a/processor/helpers.sh
+++ b/processor/helpers.sh
@@ -16,19 +16,19 @@ escape_url() {
}
get_basepath() {
- url_file=url.meta
+ url_file="$1"url
redo-ifchange "$url_file"
base_url=`cat "$url_file" | head -1`
url_protocol=`echo $base_url | cut -d ':' -f 1`
url_basepath=`echo $base_url | cut -d '/' -f 3-`
url_basepath_escaped=`escape_url "$url_basepath"`
basepath="$url_protocol""://""$url_basepath_escaped"
- echo "$basepath"
+ printf "%s" "$basepath"
}
get_source_file() {
- md_file="${1%.*}.md"
- rst_file="${1%.*}.rst"
+ md_file="../${1%.*}.md"
+ rst_file="../${1%.*}.rst"
if [ -f "$rst_file" ]; then
src_file="$rst_file"
elif [ -f "$md_file" ]; then
@@ -37,5 +37,15 @@ get_source_file() {
exit 1
fi
redo-ifchange "$src_file"
- printf "$src_file"
+ printf "%s" "$src_file"
+}
+
+prep_sed () {
+ # Escape characters that confuse sed in a replacement string. Also replace
+ # occurences of % (which the templating uses as a variable marker) with
+ # non-printable placeholder \a (clear input of it first), to be replaced by
+ # % again when the templating has finished (so that no replacement string gets
+ # interpreted by the templating).
+ sedsafe_pattern='s/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g; $!s/$/\\/g; '
+ sed "$sedsafe_pattern" | tr -d '\a' | tr '%' '\a'
}