Disable buttons/links to share data with other websites depending on env variables

This commit is contained in:
Vipin Ajayakumar
2024-09-28 16:12:43 +01:00
parent e4092a6be2
commit f66331852e
12 changed files with 98 additions and 44 deletions
+5 -2
View File
@@ -1,2 +1,5 @@
MERMAID_DOMAIN="mermaid.live" MERMAID_DOMAIN=''
MERMAID_ANALYTICS_URL="https://p.mermaid.live" MERMAID_ANALYTICS_URL=''
MERMAID_RENDERER_URL='https://mermaid.ink'
MERMAID_KROKI_RENDERER='https://kroki.io'
MERMAID_IS_ENABLED_MERMAID_CHART_LINKS=''
+3
View File
@@ -23,6 +23,9 @@ jobs:
env: env:
MERMAID_DOMAIN: 'mermaid.live' MERMAID_DOMAIN: 'mermaid.live'
MERMAID_ANALYTICS_URL: 'https://p.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: | run: |
export DEPLOY=true export DEPLOY=true
[ "$GITHUB_EVENT_NAME" != "pull_request" ] && rm -rf docs/_app/ [ "$GITHUB_EVENT_NAME" != "pull_request" ] && rm -rf docs/_app/
+1 -1
View File
@@ -11,4 +11,4 @@ yarn-error.log
/snapshots.js /snapshots.js
/cypress/downloads /cypress/downloads
/cypress/videos /cypress/videos
/cypress/screenshots /cypress/screenshots
+1
View File
@@ -18,6 +18,7 @@ ARG MERMAID_RENDERER_URL
ARG MERMAID_KROKI_RENDERER_URL ARG MERMAID_KROKI_RENDERER_URL
ARG MERMAID_ANALYTICS_URL ARG MERMAID_ANALYTICS_URL
ARG MERMAID_DOMAIN ARG MERMAID_DOMAIN
ARG MERMAID_IS_ENABLED_MERMAID_CHART_LINKS
COPY . ./ COPY . ./
+20 -3
View File
@@ -29,13 +29,18 @@ docker run --platform linux/amd64 --publish 8000:8080 ghcr.io/mermaid-js/mermaid
### To configure renderer URL ### To configure renderer URL
When building set the MERMAID_RENDERER_URL build argument to the rendering service. When building set the MERMAID_RENDERER_URL build argument to the rendering
Default is `https://mermaid.ink` service.
Example:
Default is`https://mermaid.ink`.
Set to empty string to disable PNG and SVG links under Actions
### To configure Kroki Instance URL ### To configure Kroki Instance URL
When building set the MERMAID_KROKI_RENDERER_URL build argument to your Kroki instance. When building set the MERMAID_KROKI_RENDERER_URL build argument to your Kroki
instance.
Default is `https://kroki.io` Default is `https://kroki.io`
Set to empty string to disable Kroki link under Actions
### To configure Analytics ### To configure Analytics
@@ -43,6 +48,18 @@ When building set the MERMAID_ANALYTICS_URL build argument to your plausible ins
Default is empty, disabling analytics. 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 ### Development
```bash ```bash
+3
View File
@@ -1,3 +1,6 @@
[build.environment] [build.environment]
MERMAID_ANALYTICS_URL = 'https://p.mermaid.live' MERMAID_ANALYTICS_URL = 'https://p.mermaid.live'
MERMAID_DOMAIN = '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'
+1
View File
@@ -5,6 +5,7 @@ interface ImportMetaEnv {
readonly MERMAID_KROKI_RENDERER_URL?: string; readonly MERMAID_KROKI_RENDERER_URL?: string;
readonly MERMAID_ANALYTICS_URL?: string; readonly MERMAID_ANALYTICS_URL?: string;
readonly MERMAID_DOMAIN?: string; readonly MERMAID_DOMAIN?: string;
readonly MERMAID_IS_ENABLED_MERMAID_CHART_LINKS?: string;
// more env variables... // more env variables...
} }
+29 -23
View File
@@ -197,21 +197,25 @@ ${svgString}`);
<button id="downloadSVG" class="action-btn flex-grow" on:click={onDownloadSVG}> <button id="downloadSVG" class="action-btn flex-grow" on:click={onDownloadSVG}>
<i class="fas fa-download mr-2" /> SVG <i class="fas fa-download mr-2" /> SVG
</button> </button>
<a target="_blank" rel="noreferrer" class="flex-grow" href={iUrl}> {#if rendererUrl}
<button class="action-btn w-full"> <a target="_blank" rel="noreferrer" class="flex-grow" href={iUrl}>
<i class="fas fa-external-link-alt mr-2" /> PNG <button class="action-btn w-full">
</button> <i class="fas fa-external-link-alt mr-2" /> PNG
</a> </button>
<a target="_blank" rel="noreferrer" class="flex-grow" href={svgUrl}> </a>
<button class="action-btn w-full"> <a target="_blank" rel="noreferrer" class="flex-grow" href={svgUrl}>
<i class="fas fa-external-link-alt mr-2" /> SVG <button class="action-btn w-full">
</button> <i class="fas fa-external-link-alt mr-2" /> SVG
</a> </button>
<a target="_blank" rel="noreferrer" class="flex-grow" href={krokiUrl}> </a>
<button class="action-btn w-full"> {/if}
<i class="fas fa-external-link-alt mr-2" /> Kroki {#if krokiRendererUrl}
</button> <a target="_blank" rel="noreferrer" class="flex-grow" href={krokiUrl}>
</a> <button class="action-btn w-full">
<i class="fas fa-external-link-alt mr-2" /> Kroki
</button>
</a>
{/if}
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
PNG size PNG size
@@ -238,14 +242,16 @@ ${svgString}`);
{/if} {/if}
</div> </div>
<div class="flex w-full items-center gap-2"> {#if rendererUrl}
<input class="input" id="markdown" type="text" value={mdCode} on:click={onCopyMarkdown} /> <div class="flex w-full items-center gap-2">
<label for="markdown"> <input class="input" id="markdown" type="text" value={mdCode} on:click={onCopyMarkdown} />
<button class="btn btn-primary btn-md flex-auto" on:click={onCopyMarkdown}> <label for="markdown">
Copy Markdown <button class="btn btn-primary btn-md flex-auto" on:click={onCopyMarkdown}>
</button> Copy Markdown
</label> </button>
</div> </label>
</div>
{/if}
<div class="flex w-full items-center gap-2"> <div class="flex w-full items-center gap-2">
<input <input
+13 -5
View File
@@ -7,9 +7,13 @@
</script> </script>
<script lang="ts"> <script lang="ts">
import { env } from '$lib/util/env';
import Theme from './Theme.svelte'; import Theme from './Theme.svelte';
import { dismissPromotion, getActivePromotion } from '$lib/util/promos/promo'; import { dismissPromotion, getActivePromotion } from '$lib/util/promos/promo';
import Privacy from './Privacy.svelte'; import Privacy from './Privacy.svelte';
const { isEnabledMermaidChartLinks } = env;
let isMenuOpen = false; let isMenuOpen = false;
function toggleMenu() { function toggleMenu() {
@@ -22,7 +26,8 @@
icon?: string; icon?: string;
img?: string; img?: string;
} }
const links: Link[] = [
let links: Link[] = [
{ {
title: 'Documentation', title: 'Documentation',
href: 'https://mermaid.js.org/intro/getting-started.html' href: 'https://mermaid.js.org/intro/getting-started.html'
@@ -42,13 +47,16 @@
{ {
href: 'https://github.com/mermaid-js/mermaid-live-editor', href: 'https://github.com/mermaid-js/mermaid-live-editor',
icon: 'fab fa-github fa-lg' icon: 'fab fa-github fa-lg'
},
{
href: 'https://mermaidchart.com',
img: './mermaidchart-logo.svg'
} }
]; ];
if (isEnabledMermaidChartLinks) {
links.push({
href: 'https://mermaidchart.com',
img: './mermaidchart-logo.svg'
});
}
let activePromotion = getActivePromotion(); let activePromotion = getActivePromotion();
const trackBannerClick = () => { const trackBannerClick = () => {
+4 -3
View File
@@ -1,6 +1,7 @@
export const env = { export const env = {
rendererUrl: import.meta.env.MERMAID_RENDERER_URL ?? 'https://mermaid.ink', rendererUrl: import.meta.env.MERMAID_RENDERER_URL ?? '',
krokiRendererUrl: import.meta.env.MERMAID_KROKI_RENDERER_URL ?? 'https://kroki.io', krokiRendererUrl: import.meta.env.MERMAID_KROKI_RENDERER_URL ?? '',
analyticsUrl: import.meta.env.MERMAID_ANALYTICS_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; } as const;
+6
View File
@@ -1,6 +1,7 @@
import { writable, type Writable, get } from 'svelte/store'; import { writable, type Writable, get } from 'svelte/store';
import { persist, localStorage } from '../persist'; import { persist, localStorage } from '../persist';
import August2024 from './August2024.svelte'; import August2024 from './August2024.svelte';
import { env } from '$lib/util/env';
interface Promotion { interface Promotion {
id: string; id: string;
@@ -35,6 +36,11 @@ const dismissedPromotionsStore: Writable<string[]> = persist(
); );
export const getActivePromotion = (): Promotion | undefined => { export const getActivePromotion = (): Promotion | undefined => {
const { isEnabledMermaidChartLinks } = env;
if (!isEnabledMermaidChartLinks) {
return;
}
const dismissedPromotions = get(dismissedPromotionsStore); const dismissedPromotions = get(dismissedPromotionsStore);
const now = new Date(); const now = new Date();
return promotions return promotions
+12 -7
View File
@@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import { dev } from '$app/environment'; import { dev } from '$app/environment';
import { base } from '$app/paths'; import { base } from '$app/paths';
import { env } from '$lib/util/env';
import Actions from '$lib/components/Actions.svelte'; import Actions from '$lib/components/Actions.svelte';
import Card from '$lib/components/Card/Card.svelte'; import Card from '$lib/components/Card/Card.svelte';
import Editor from '$lib/components/Editor.svelte'; import Editor from '$lib/components/Editor.svelte';
@@ -13,6 +14,8 @@
import { cmdKey, initHandler, syncDiagram } from '$lib/util/util'; import { cmdKey, initHandler, syncDiagram } from '$lib/util/util';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
const { isEnabledMermaidChartLinks } = env;
const MCBaseURL = dev ? 'http://localhost:5174' : 'https://mermaidchart.com'; const MCBaseURL = dev ? 'http://localhost:5174' : 'https://mermaidchart.com';
const docURLBase = 'https://mermaid.js.org'; const docURLBase = 'https://mermaid.js.org';
const docMap: DocumentationConfig = { const docMap: DocumentationConfig = {
@@ -215,13 +218,15 @@
target="_blank" target="_blank"
class="btn btn-secondary btn-xs gap-1" class="btn btn-secondary btn-xs gap-1"
title="View diagram in new page"><i class="fas fa-external-link-alt" />Full screen</a> title="View diagram in new page"><i class="fas fa-external-link-alt" />Full screen</a>
<a {#if isEnabledMermaidChartLinks}
href={`${MCBaseURL}/app/plugin/save?state=${$stateStore.serialized}`} <a
target="_blank" href={`${MCBaseURL}/app/plugin/save?state=${$stateStore.serialized}`}
class="btn btn-secondary btn-xs gap-1 bg-[#FF3570]" target="_blank"
title="Save diagram in Mermaid Chart" class="btn btn-secondary btn-xs gap-1 bg-[#FF3570]"
><img src="./mermaidchart-logo.svg" class="h-5 w-5" alt="Mermaid chart logo" />Save to title="Save diagram in Mermaid Chart"
Mermaid Chart</a> ><img src="./mermaidchart-logo.svg" class="h-5 w-5" alt="Mermaid chart logo" />Save to
Mermaid Chart</a>
{/if}
</div> </div>
<div class="flex-1 overflow-auto"> <div class="flex-1 overflow-auto">