diff --git a/front/.gitignore b/front/.gitignore index e77b54d0..b6f01e2c 100644 --- a/front/.gitignore +++ b/front/.gitignore @@ -5,4 +5,5 @@ /dist/webpack.config.js /dist/webpack.config.js.map /dist/src -*.sh \ No newline at end of file +*.sh +!templater.sh diff --git a/front/Dockerfile b/front/Dockerfile index 6c79ad6e..b0d17877 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -11,5 +11,6 @@ COPY --from=builder --chown=docker:docker /var/www/messages/generated /var/www/h RUN yarn install ENV NODE_ENV=production +ENV STARTUP_COMMAND_0="./templater.sh" ENV STARTUP_COMMAND_1="yarn run build" ENV APACHE_DOCUMENT_ROOT=dist/ diff --git a/front/dist/ga.html.tmpl b/front/dist/ga.html.tmpl new file mode 100644 index 00000000..ace84b39 --- /dev/null +++ b/front/dist/ga.html.tmpl @@ -0,0 +1,9 @@ + + + diff --git a/front/dist/index.html b/front/dist/index.html.tmpl similarity index 95% rename from front/dist/index.html rename to front/dist/index.html.tmpl index 9a197822..a2b44788 100644 --- a/front/dist/index.html +++ b/front/dist/index.html.tmpl @@ -6,15 +6,8 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> - - - + + diff --git a/front/templater.sh b/front/templater.sh new file mode 100755 index 00000000..aa6534b3 --- /dev/null +++ b/front/templater.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -x +set -o nounset errexit +template_file_index=dist/index.html.tmpl +generated_file_index=dist/index.html +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 +ANALYTICS_CODE_PATH="${ANALYTICS_CODE_PATH:-dist/ga.html.tmpl}" + +if [[ "${INSERT_ANALYTICS:-NO}" == "NO" ]]; then + echo "" > "${tmp_trackcodefile}" +fi + +# Automatically insert analytics if TRACKING_NUMBER is set +if [[ "${TRACKING_NUMBER:-}" != "" || "${INSERT_ANALYTICS:-NO}" != "NO" ]]; then + echo "Templating code from ${ANALYTICS_CODE_PATH}" + sed "s##${TRACKING_NUMBER:-}#g" "${ANALYTICS_CODE_PATH}" > "$tmp_trackcodefile" +fi + +echo "Templating ${generated_file_index} from ${template_file_index}" +sed "//r ${tmp_trackcodefile}" "${template_file_index}" > "${generated_file_index}" +rm "${tmp_trackcodefile}"