summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Fincato <work@andrefincato.info>2021-02-21 23:20:27 +0100
committerAndré Fincato <work@andrefincato.info>2021-02-21 23:20:27 +0100
commit76b7d4bf20b01f2509c4d58208ff62c3ec5264c9 (patch)
tree12f5aa55253a380e56663bd48acac37aa74ad111
parentbde9f5b66ed50b316373c4e54d1e61107dee185e (diff)
add command to read article template
-rwxr-xr-xbuild-page.sh11
1 files changed, 9 insertions, 2 deletions
diff --git a/build-page.sh b/build-page.sh
index 197e5c2..3c56bcd 100755
--- a/build-page.sh
+++ b/build-page.sh
@@ -43,6 +43,13 @@ OUTPUT_PATH=$(join / ${OUTPUT_ARRAY[@]})
COMMIT_DATE=$(git log -n 1 --pretty=format:%cd --date=format:'%Y-%m-%dT%H:%M:%S' -- $INPUT)
COMMIT_HASH=$(git log -n 1 --pretty=format:%h -- $INPUT)
-pandoc $INPUT --template $TEMPLATE -o $OUTPUT_PATH -V commit_date=$COMMIT_DATE -V commit_hash=$COMMIT_HASH
+#-- fetch template value from article YAML head block, eg `template: <string>`
+#-- the rg command:
+# - `N` does not print line number match
+# - `P` uses another regex engine (PCRE2) to perform a look-around operation
+# - `o` prints "only matching"
+TEMPLATE=$(rg -NPo '(?<=template: )\w.+' $INPUT)
-printf "'$1' converted to html and saved in '$OUTPUT', with commit-hash $COMMIT_HASH and commit-date $COMMIT_DATE.\n"
+pandoc $INPUT --template templates/$TEMPLATE -o $OUTPUT_PATH -V commit_date=$COMMIT_DATE -V commit_hash=$COMMIT_HASH
+
+printf "'$1' converted to html and saved in '$OUTPUT', with template $TEMPLATE, with commit-hash $COMMIT_HASH and commit-date $COMMIT_DATE.\n"