feat: switched to NEXT_PUBLIC_HEAD_SCRIPTS for injecting analytic scrips

This commit is contained in:
2026-08-20 03:43:40 +03:00
parent 6c57713945
commit ffa3570427
4 changed files with 14 additions and 57 deletions

View File

@@ -1,3 +1,10 @@
NEXT_PUBLIC_BASE_PATH=
NEXT_PUBLIC_MB_IS_DEMO_MODE=true
NODE_ENV=production
NODE_ENV=production
MB_JWT_SECRET=
MB_DISABLE_FILE_UPLOADS=false
MB_OAUTH_ENCRYPTION_KEY=
MB_REALTIME_SSE_KEY=
MB_REALTIME_WS=
MB_DISABLE_ADMIN_MUTATIONS=false
MB_DISABLE_CONFIG_MUTATIONS=false

View File

@@ -5,6 +5,11 @@ WORKDIR /app
COPY mb/package.json mb/package-lock.json ./
RUN npm ci
ENV NEXT_PUBLIC_BASE_PATH=""
ENV NEXT_PUBLIC_MB_IS_DEMO_MODE="true"
ENV NODE_ENV=production
ENV NEXT_PUBLIC_HEAD_SCRIPTS="<script defer data-domain=\"demo.mantisbase.com\" src=\"https://analytics.codeart.co.ke/js/script.file-downloads.hash.outbound-links.pageview-props.revenue.tagged-events.js\"></script><script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>"
COPY mb/ ./
COPY next.config.demo.mjs ./next.config.mjs
COPY .env-prod .env
@@ -15,18 +20,9 @@ RUN npm run build
FROM allankoech/mantisbase:beta
WORKDIR /mb
ENV NEXT_PUBLIC_BASE_PATH=""
ENV NEXT_PUBLIC_MB_IS_DEMO_MODE="true"
ENV NODE_ENV=production
COPY --from=ui-builder /app/out/ ./public/
COPY db/data ./data-default/
COPY scripts/docker-entrypoint.sh /entrypoint.sh
# Inject analytics script
COPY inject-analytics.sh /inject-analytics.sh
RUN chmod +x /inject-analytics.sh
RUN /inject-analytics.sh /mb/public
EXPOSE 80
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]

View File

@@ -1,46 +0,0 @@
#!/bin/sh
set -eu
OUTPUT_DIR="${1:-./out}"
ANALYTICS_SCRIPT="${ANALYTICS_SCRIPT:-<script defer data-domain="demo.mantisbase.com" src="https://analytics.codeart.co.ke/js/script.file-downloads.hash.outbound-links.pageview-props.revenue.tagged-events.js"></script>
<script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>
}"
if [ ! -d "$OUTPUT_DIR" ]; then
echo "Error: output directory does not exist: $OUTPUT_DIR" >&2
exit 1
fi
find "$OUTPUT_DIR" -type f -name '*.html' -print0 |
while IFS= read -r -d '' file; do
if grep -qF "$ANALYTICS_SCRIPT" "$file"; then
echo "Skipping: $file"
continue
fi
if ! grep -qi '</head>' "$file"; then
echo "Warning: no </head> found: $file" >&2
continue
fi
tmp="${file}.tmp"
awk -v script="$ANALYTICS_SCRIPT" '
BEGIN {
IGNORECASE = 1
injected = 0
}
!injected && /<\/head>/ {
sub(/<\/head>/, script "</head>")
injected = 1
}
{ print }
' "$file" > "$tmp"
mv "$tmp" "$file"
echo "Injected: $file"
done

2
mb

Submodule mb updated: 3b227cb720...7134c7df5b