From 69fe30f8719f86c66109b017a47d2c6ca7d53c45 Mon Sep 17 00:00:00 2001 From: nemanjam Date: Sun, 29 Sep 2024 18:07:28 +0200 Subject: [PATCH] add env var PLAUSIBLE_DOMAIN and set it for every mirror --- .env.development.example | 6 +++++- .env.production.example | 4 ++++ .github/workflows/bash__deploy-nginx.yml | 3 +++ .../workflows/default__build-push-docker.yml | 2 ++ .github/workflows/default__deploy-nginx.yml | 1 + .github/workflows/gh-pages__deploy-astro.yml | 1 + .github/workflows/gh-pages__deploy-manual.yml | 1 + docker-compose.yml | 2 ++ docker/Dockerfile | 4 ++++ docs/working-notes/todo3.md | 1 + package.json | 8 +++---- src/components/BaseHead.astro | 7 +++---- src/config/client.ts | 3 ++- src/config/process-env.ts | 8 +++++++ src/schemas/config.ts | 21 +++++++++++++++++-- src/utils/urls.ts | 1 + src/utils/validation.ts | 11 ++++++++-- 17 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 src/utils/urls.ts diff --git a/.env.development.example b/.env.development.example index 906b7f1..f0cb671 100644 --- a/.env.development.example +++ b/.env.development.example @@ -6,5 +6,9 @@ SITE_URL=http://localhost:3000 # always true in development, set only on prod build # PREVIEW_MODE= -# plausible analytics url +# Plausible analytics url PLAUSIBLE_SCRIPT_URL= + +# for mirrors, hostname set in Plausible dashboard +# if not set, defaults to SITE_URL without https:// +PLAUSIBLE_DOMAIN= diff --git a/.env.production.example b/.env.production.example index b83fc74..828816e 100644 --- a/.env.production.example +++ b/.env.production.example @@ -10,3 +10,7 @@ PREVIEW_MODE= # plausible analytics url PLAUSIBLE_SCRIPT_URL= + +# for mirrors, hostname set in Plausible dashboard +# if not set, defaults to SITE_URL without https:// +PLAUSIBLE_DOMAIN=nemanjamitic.com \ No newline at end of file diff --git a/.github/workflows/bash__deploy-nginx.yml b/.github/workflows/bash__deploy-nginx.yml index ddc0767..c28e547 100644 --- a/.github/workflows/bash__deploy-nginx.yml +++ b/.github/workflows/bash__deploy-nginx.yml @@ -2,6 +2,7 @@ name: Deploy Nginx with bash file on: push: + # this one is enabled branches: - 'main' tags: @@ -15,6 +16,8 @@ env: SITE_URL: 'https://nemanjamitic.com' PLAUSIBLE_SCRIPT_URL: 'https://plausible.arm1.nemanjamitic.com/js/script.js' SSH_ALIAS: arm1 + # can be omitted for main domain, will default to SITE_URL + # PLAUSIBLE_DOMAIN: 'nemanjamitic.com' jobs: deploy: diff --git a/.github/workflows/default__build-push-docker.yml b/.github/workflows/default__build-push-docker.yml index aa0654a..dad69e4 100644 --- a/.github/workflows/default__build-push-docker.yml +++ b/.github/workflows/default__build-push-docker.yml @@ -16,6 +16,7 @@ env: SITE_URL_ARM64: 'https://nmc-docker.arm1.nemanjamitic.com' SITE_URL_AMD64: 'https://nmc-docker.local.nemanjamitic.com' PLAUSIBLE_SCRIPT_URL: 'https://plausible.arm1.nemanjamitic.com/js/script.js' + PLAUSIBLE_DOMAIN: 'nemanjamitic.com' jobs: build: @@ -87,6 +88,7 @@ jobs: build-args: | "ARG_SITE_URL=${{ env.SITE_URL }}" "ARG_PLAUSIBLE_SCRIPT_URL=${{ env.PLAUSIBLE_SCRIPT_URL }}" + "ARG_PLAUSIBLE_DOMAIN=${{ env.PLAUSIBLE_DOMAIN }}" push: true tags: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest # disabled metadata step diff --git a/.github/workflows/default__deploy-nginx.yml b/.github/workflows/default__deploy-nginx.yml index 4a1465b..e7ff8f0 100644 --- a/.github/workflows/default__deploy-nginx.yml +++ b/.github/workflows/default__deploy-nginx.yml @@ -14,6 +14,7 @@ on: env: SITE_URL: 'https://nemanjamitic.com' PLAUSIBLE_SCRIPT_URL: 'https://plausible.arm1.nemanjamitic.com/js/script.js' + PLAUSIBLE_DOMAIN: 'nemanjamitic.com' jobs: deploy: diff --git a/.github/workflows/gh-pages__deploy-astro.yml b/.github/workflows/gh-pages__deploy-astro.yml index 1312917..7151d79 100644 --- a/.github/workflows/gh-pages__deploy-astro.yml +++ b/.github/workflows/gh-pages__deploy-astro.yml @@ -24,6 +24,7 @@ permissions: env: SITE_URL: 'https://nemanjam.github.io' PLAUSIBLE_SCRIPT_URL: 'https://plausible.arm1.nemanjamitic.com/js/script.js' + PLAUSIBLE_DOMAIN: 'nemanjamitic.com' jobs: # build with astro action, unusable for monorepo diff --git a/.github/workflows/gh-pages__deploy-manual.yml b/.github/workflows/gh-pages__deploy-manual.yml index 416a55a..7247d2d 100644 --- a/.github/workflows/gh-pages__deploy-manual.yml +++ b/.github/workflows/gh-pages__deploy-manual.yml @@ -21,6 +21,7 @@ permissions: env: SITE_URL: 'https://nemanjam.github.io' PLAUSIBLE_SCRIPT_URL: 'https://plausible.arm1.nemanjamitic.com/js/script.js' + PLAUSIBLE_DOMAIN: 'nemanjamitic.com' jobs: build-manual: diff --git a/docker-compose.yml b/docker-compose.yml index cb28779..75a3654 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,8 @@ services: ARG_SITE_URL: 'http://localhost:8080' # make separate script with localhost enabled ARG_PLAUSIBLE_SCRIPT_URL: 'https://plausible.arm1.nemanjamitic.com/js/script.js' + # will trigger analytics + ARG_PLAUSIBLE_DOMAIN: 'nemanjamitic.com' # platform: linux/arm64 platform: linux/amd64 diff --git a/docker/Dockerfile b/docker/Dockerfile index f33ca2a..8d623f8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -29,6 +29,10 @@ ARG ARG_PLAUSIBLE_SCRIPT_URL ENV PLAUSIBLE_SCRIPT_URL=$ARG_PLAUSIBLE_SCRIPT_URL RUN echo "PLAUSIBLE_SCRIPT_URL=$PLAUSIBLE_SCRIPT_URL" +ARG ARG_PLAUSIBLE_DOMAIN +ENV PLAUSIBLE_DOMAIN=$ARG_PLAUSIBLE_DOMAIN +RUN echo "PLAUSIBLE_DOMAIN=$PLAUSIBLE_DOMAIN" + RUN yarn build FROM nginx:stable-alpine3.17-slim AS runtime diff --git a/docs/working-notes/todo3.md b/docs/working-notes/todo3.md index b567783..6211d04 100644 --- a/docs/working-notes/todo3.md +++ b/docs/working-notes/todo3.md @@ -550,5 +550,6 @@ restructure folders, folder name, mdx and images in same folder content collections to content layer fix plausible for all subdomains gallery astro image +prettyPrintObject in_ dev works after page load, ok ------------ ``` diff --git a/package.json b/package.json index 6b021bc..16a149c 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "start": "serve ./dist", "preview": "astro preview", "build": "astro build", - "build:nginx": "SITE_URL='https://nemanjamitic.com' PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' astro build", - "build:nginx:local": "SITE_URL='https://blog.local.nemanjamitic.com' PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' astro build", + "build:nginx": "SITE_URL='https://nemanjamitic.com' PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' PLAUSIBLE_DOMAIN='nemanjamitic.com' astro build", + "build:nginx:local": "SITE_URL='https://blog.local.nemanjamitic.com' PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' PLAUSIBLE_DOMAIN='nemanjamitic.com' astro build", "astro": "astro", "sync": "astro sync", "lint": "eslint --ext .astro,.tsx,.ts,.js,.mdx src", @@ -19,8 +19,8 @@ "deploy:nginx:local": "bash scripts/deploy-nginx.sh '~/traefik-proxy/apps/nmc-nginx-with-volume/website' lxc11", "deploy:docker": "bash scripts/deploy-docker.sh arm1 '~/traefik-proxy/apps/nmc-docker' nemanjamitic/nemanjam.github.io", "deploy:docker:local": "bash scripts/deploy-docker.sh lxc11 '~/traefik-proxy/apps/nmc-docker' nemanjamitic/nemanjam.github.io", - "docker:build:push:arm": "docker buildx build -f ./docker/Dockerfile -t nemanjamitic/nemanjam.github.io --build-arg ARG_SITE_URL='https://nmc-docker.arm1.nemanjamitic.com' --build-arg ARG_PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' --platform linux/arm64 --push .", - "docker:build:push:x86": "docker buildx build -f ./docker/Dockerfile -t nemanjamitic/nemanjam.github.io --build-arg ARG_SITE_URL='https://nmc-docker.local.nemanjamitic.com' --build-arg ARG_PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' --platform linux/amd64 --push .", + "docker:build:push:arm": "docker buildx build -f ./docker/Dockerfile -t nemanjamitic/nemanjam.github.io --build-arg ARG_SITE_URL='https://nmc-docker.arm1.nemanjamitic.com' --build-arg ARG_PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' --build-arg ARG_PLAUSIBLE_DOMAIN='nemanjamitic.com' --platform linux/arm64 --push .", + "docker:build:push:x86": "docker buildx build -f ./docker/Dockerfile -t nemanjamitic/nemanjam.github.io --build-arg ARG_SITE_URL='https://nmc-docker.local.nemanjamitic.com' --build-arg ARG_PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' --build-arg ARG_PLAUSIBLE_DOMAIN='nemanjamitic.com' --platform linux/amd64 --push .", "docker:push": "docker push nemanjamitic/nemanjam.github.io", "dc:up": "docker compose up --build --force-recreate -d" }, diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index b7bba8b..22b5675 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -13,10 +13,8 @@ import { filterUndefined } from '@/utils/objects'; import type { Metadata } from '@/types/common'; -const { AUTHOR_NAME, PLAUSIBLE_SCRIPT_URL } = CONFIG_CLIENT; +const { AUTHOR_NAME, PLAUSIBLE_SCRIPT_URL, PLAUSIBLE_DOMAIN } = CONFIG_CLIENT; -// this must be the same for all mirrors -const PLAUSIBLE_DATA_DOMAIN = 'nemanjamitic.com'; export interface BaseHeadProps { metadata: Metadata; } @@ -109,11 +107,12 @@ const ogImageUrl = new URL(image, url); PLAUSIBLE_SCRIPT_URL && ( <> + {/* PLAUSIBLE_DOMAIN must be the same for all mirrors */}