From 431a63f7009ff4dcacb8b397ae5a7926687cc432 Mon Sep 17 00:00:00 2001 From: Vipin Ajayakumar Date: Fri, 6 Sep 2024 21:35:19 +0100 Subject: [PATCH] Disable buttons/links to share data with other websites depending on env variables --- .env | 7 +++-- .github/workflows/deploy.yml | 3 ++ .gitignore | 1 + Dockerfile | 1 + README.md | 16 ++++++++-- netlify.toml | 3 ++ src/env.d.ts | 1 + src/lib/components/Actions.svelte | 52 +++++++++++++++++-------------- src/lib/components/Navbar.svelte | 38 +++++++++++++--------- src/lib/util/env.ts | 7 +++-- src/routes/edit/+page.svelte | 19 ++++++----- 11 files changed, 96 insertions(+), 52 deletions(-) diff --git a/.env b/.env index 5d946ab46..f9afb8485 100644 --- a/.env +++ b/.env @@ -1,2 +1,5 @@ - MERMAID_DOMAIN="mermaid.live" - MERMAID_ANALYTICS_URL="https://p.mermaid.live" + MERMAID_DOMAIN='' + MERMAID_ANALYTICS_URL='' + MERMAID_RENDERER_URL='' + MERMAID_KROKI_RENDERER='' + MERMAID_IS_ENABLED_MERMAID_CHART_LINKS='' \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 87b64abc6..8ff007f2c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,6 +23,9 @@ jobs: env: MERMAID_DOMAIN: 'mermaid.live' MERMAID_ANALYTICS_URL: 'https://p.mermaid.live' + MERMAID_RENDERER_URL: 'https://mermaid.ink' + MERMAID_KROKI_RENDERER_URL: 'https://kroki.io' + MERMAID_IS_ENABLED_MERMAID_CHART_LINKS: 'True' run: | export DEPLOY=true [ "$GITHUB_EVENT_NAME" != "pull_request" ] && rm -rf docs/_app/ diff --git a/.gitignore b/.gitignore index 381928d77..b27eef2de 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ yarn-error.log /cypress/downloads /cypress/videos /cypress/screenshots +.vscode \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b400b6a70..8335f14e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ ARG MERMAID_RENDERER_URL ARG MERMAID_KROKI_RENDERER_URL ARG MERMAID_ANALYTICS_URL ARG MERMAID_DOMAIN +ARG MERMAID_IS_ENABLED_MERMAID_CHART_LINKS COPY . ./ diff --git a/README.md b/README.md index 746855583..1cc4b746d 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,12 @@ docker run --platform linux/amd64 --publish 8000:8080 ghcr.io/mermaid-js/mermaid ### To configure renderer URL When building set the MERMAID_RENDERER_URL build argument to the rendering service. -Default is `https://mermaid.ink` +Default is empty disabling PNG and SVG links under Actions ### To configure Kroki Instance URL When building set the MERMAID_KROKI_RENDERER_URL build argument to your Kroki instance. -Default is `https://kroki.io` +Default is empty disabling Kroki link under Actions ### To configure Analytics @@ -43,6 +43,18 @@ When building set the MERMAID_ANALYTICS_URL build argument to your plausible ins Default is empty, disabling analytics. +### To enable Mermaid Chart links and promotion + +When building set the MERMAID_IS_ENABLED_MERMAID_CHART_LINKS build argument to `True` + +Default is empty, disabling button to save to Mermaid Chart and promotional banner. + +### To update the Security modal + +The modal shown on clicking the security link assumes analytics, renderer, Kroki +and Mermaid chart are enabled. You can update it by modifying `Privacy.svelte` +if you wish. + ### Development ```bash diff --git a/netlify.toml b/netlify.toml index 4b646fa7f..7947c7978 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,3 +1,6 @@ [build.environment] MERMAID_ANALYTICS_URL = 'https://p.mermaid.live' MERMAID_DOMAIN = 'mermaid.live' + MERMAID_RENDERER_URL = 'https://mermaid.ink' + MERMAID_KROKI_RENDERER_URL = 'https://kroki.io' + MERMAID_IS_ENABLED_MERMAID_CHART_LINKS ='True' \ No newline at end of file diff --git a/src/env.d.ts b/src/env.d.ts index ec4a2ff4b..d02631111 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -5,6 +5,7 @@ interface ImportMetaEnv { readonly MERMAID_KROKI_RENDERER_URL?: string; readonly MERMAID_ANALYTICS_URL?: string; readonly MERMAID_DOMAIN?: string; + readonly MERMAID_IS_ENABLED_MERMAID_CHART_LINKS?: string; // more env variables... } diff --git a/src/lib/components/Actions.svelte b/src/lib/components/Actions.svelte index 9c0bd1c4c..a222e57af 100644 --- a/src/lib/components/Actions.svelte +++ b/src/lib/components/Actions.svelte @@ -197,21 +197,25 @@ ${svgString}`); - - - - - - - - - + {#if rendererUrl} + + + + + + + {/if} + {#if krokiRendererUrl} + + + + {/if}
PNG size @@ -238,14 +242,16 @@ ${svgString}`); {/if}
-
- - -
+ {#if rendererUrl} +
+ + +
+ {/if}
-{#if activePromotion} +{#if activePromotion && isEnabledMermaidChartLinks}
- {#each links as { title, href, icon, img }} -
  • - - {#if icon} - - {:else if img} - {title} - {/if} - {#if title} - {title} - {/if} - -
  • + {#each links as { title, href, icon, img, isHidden }} + {#if !isHidden} +
  • + + {#if icon} + + {:else if img} + {title} + {/if} + {#if title} + {title} + {/if} + +
  • + {/if} {/each}
    diff --git a/src/lib/util/env.ts b/src/lib/util/env.ts index d19f1a95d..7a52a4220 100644 --- a/src/lib/util/env.ts +++ b/src/lib/util/env.ts @@ -1,6 +1,7 @@ export const env = { - rendererUrl: import.meta.env.MERMAID_RENDERER_URL ?? 'https://mermaid.ink', - krokiRendererUrl: import.meta.env.MERMAID_KROKI_RENDERER_URL ?? 'https://kroki.io', + rendererUrl: import.meta.env.MERMAID_RENDERER_URL ?? '', + krokiRendererUrl: import.meta.env.MERMAID_KROKI_RENDERER_URL ?? '', analyticsUrl: import.meta.env.MERMAID_ANALYTICS_URL ?? '', - domain: import.meta.env.MERMAID_DOMAIN ?? 'mermaid.live' + domain: import.meta.env.MERMAID_DOMAIN ?? '', + isEnabledMermaidChartLinks: import.meta.env.MERMAID_IS_ENABLED_MERMAID_CHART_LINKS == 'True' } as const; diff --git a/src/routes/edit/+page.svelte b/src/routes/edit/+page.svelte index 4d3385740..b3623afb3 100644 --- a/src/routes/edit/+page.svelte +++ b/src/routes/edit/+page.svelte @@ -1,6 +1,7 @@