quartz-docker/entrypoint.sh

69 lines
2.9 KiB
Bash

#!/bin/bash
set -e
CONFIG_FILE="/usr/share/nginx/html/quartz.config.ts"
TEMP_FILE="${CONFIG_FILE}.tmp"
replace_text() {
local search="$1"
local replace="$2"
# file var with default value
local file="${3:-$CONFIG_FILE}"
if [[ -z "$search" || -z "$replace" ]]; then
echo "Error: Missing arguments"
return 1
fi
# Modify a temporary file instead of the original
sed -e "s|${search}|${replace}|g" "$CONFIG_FILE" >"$TEMP_FILE" && mv "$TEMP_FILE" "$CONFIG_FILE"
}
# Quartz Config
replace_text 'pageTitle: "🪴 Quartz 4.0",' "pageTitle: \"${PAGE_TITLE}\","
replace_text 'enableSPA: true,' "enableSPA: ${ENABLE_SPA},"
replace_text 'enablePopovers: true,' "enablePopovers: ${ENABLE_POPOVERS},"
replace_text 'provider: "plausible",' "provider: \"${ANALYTICS_PROVIDER}\","
replace_text 'baseUrl: "quartz.zhao.xyz",' "baseUrl: \"${BASE_URL}\","
replace_text 'ignorePatterns: ["private", "templates"],' "ignorePatterns: [\"${IGNORE_PATTERNS//,/\", \"}\"],"
replace_text 'header: "Schibsted Grotesk",' "header: \"${TYPOGRAPHY_HEADER}\","
replace_text 'body: "Source Sans Pro",' "body: \"${TYPOGRAPHY_BODY}\","
replace_text 'code: "IBM-Plex Mono",' "code: \"${TYPOGRAPHY_CODE}\","
replace_text 'light: "#faf8f8",' "light: \"${LIGHTMODE_LIGHT}\","
replace_text 'lightgray: "#e5e5e5",' "lightgray: \"${LIGHTMODE_LIGHTGRAY}\","
replace_text 'gray: "#bbbbbb",' "gray: \"${LIGHTMODE_GRAY}\","
replace_text 'darkgray: "#4e4e4e",' "darkgray: \"${LIGHTMODE_DARKGRAY}\","
replace_text 'dark: "#2b2b2b",' "dark: \"${LIGHTMODE_DARK}\","
replace_text 'secondary: "#284b63",' "secondary: \"${LIGHTMODE_SECONDARY}\","
replace_text 'tertiary: "#84a59d",' "tertiary: \"${LIGHTMODE_TERTIARY}\","
replace_text 'highlight: "rgba(143, 159, 169, 0.15)",' "highlight: \"${LIGHTMODE_HIGHLIGHT}\","
replace_text 'light: "#161618",' "light: \"${DARKMODE_LIGHT}\","
replace_text 'lightgray: "#393639",' "lightgray: \"${DARKMODE_LIGHTGRAY}\","
replace_text 'gray: "#646464",' "gray: \"${DARKMODE_GRAY}\","
replace_text 'darkgray: "#4d4d4d",' "darkgray: \"${DARKMODE_DARKGRAY}\","
replace_text 'dark: "#ebebec",' "dark: \"${DARKMODE_DARK}\","
replace_text 'secondary: "#7b97aa",' "secondary: \"${DARKMODE_SECONDARY}\","
replace_text 'tertiary: "#84a59d",' "tertiary: \"${DARKMODE_TERTIARY}\","
replace_text 'highlight: "rgba(143, 159, 169, 0.15)",' "highlight: \"${DARKMODE_HIGHLIGHT}\","
chown nginx:nginx "$CONFIG_FILE"
echo "${BUILD_SCHEDULE} cd /usr/share/nginx/html/content && git pull >/dev/null 2>&1 && cd /usr/share/nginx/html && npx quartz build >/dev/null 2>&1" >/etc/crontabs/root
# NGINX script to sub variables in the template
/docker-entrypoint.d/20-envsubst-on-templates.sh
# ENABLE_CRON
if [[ "$ENABLE_CRON" == "true" ]]; then
echo "Cron is enabled"
crond -b
fi
echo "Starting Quartz..."
echo "Installing dependencies..."
npm i >/dev/null
echo "Building Quartz..."
npx quartz build
echo "Starting Nginx..."
exec nginx -g "daemon off;"