2021-01-19 10:46:53 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -x
|
|
|
|
set -o nounset errexit
|
2021-02-02 11:34:29 +01:00
|
|
|
template_file_index=dist/index.tmpl.html
|
2021-03-05 10:00:11 +01:00
|
|
|
generated_file_index=dist/index.tmpl.html.tmp
|
2021-01-19 10:46:53 +01:00
|
|
|
tmp_trackcodefile=/tmp/trackcode
|
|
|
|
|
|
|
|
# To inject tracking code, you have two choices:
|
|
|
|
# 1) Template using the provided google analytics
|
|
|
|
# 2) Insert with your own provided code, by overriding the ANALYTICS_CODE_PATH
|
|
|
|
# The ANALYTICS_CODE_PATH is the location of a file inside the container
|
2021-02-02 11:19:24 +01:00
|
|
|
ANALYTICS_CODE_PATH="${ANALYTICS_CODE_PATH:-dist/ga.html.tmpl}"
|
2021-01-19 10:46:53 +01:00
|
|
|
|
|
|
|
if [[ "${INSERT_ANALYTICS:-NO}" == "NO" ]]; then
|
|
|
|
echo "" > "${tmp_trackcodefile}"
|
|
|
|
fi
|
|
|
|
|
2021-01-20 17:30:11 +01:00
|
|
|
# Automatically insert analytics if GA_TRACKING_ID is set
|
|
|
|
if [[ "${GA_TRACKING_ID:-}" != "" || "${INSERT_ANALYTICS:-NO}" != "NO" ]]; then
|
2021-01-19 10:46:53 +01:00
|
|
|
echo "Templating code from ${ANALYTICS_CODE_PATH}"
|
2021-01-20 17:30:11 +01:00
|
|
|
sed "s#<!-- TRACKING NUMBER -->#${GA_TRACKING_ID:-}#g" "${ANALYTICS_CODE_PATH}" > "$tmp_trackcodefile"
|
2021-01-19 10:46:53 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Templating ${generated_file_index} from ${template_file_index}"
|
|
|
|
sed "/<!-- TRACK CODE -->/r ${tmp_trackcodefile}" "${template_file_index}" > "${generated_file_index}"
|
|
|
|
rm "${tmp_trackcodefile}"
|