Skip to content

Commit 8190a94

Browse files
authored
Merge pull request #1528 from bluprince13/feature/1511_ability-to-disable-data-share-buttons
Disable buttons/links to share data with other websites depending on environment variables
2 parents 60e2b30 + 4415849 commit 8190a94

File tree

12 files changed

+95
-44
lines changed

12 files changed

+95
-44
lines changed

.env

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
MERMAID_DOMAIN="mermaid.live"
2-
MERMAID_ANALYTICS_URL="https://p.mermaid.live"
1+
MERMAID_DOMAIN=''
2+
MERMAID_ANALYTICS_URL=''
3+
MERMAID_RENDERER_URL='https://mermaid.ink'
4+
MERMAID_KROKI_RENDERER='https://kroki.io'
5+
MERMAID_IS_ENABLED_MERMAID_CHART_LINKS=''

.github/workflows/deploy.yml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
env:
2424
MERMAID_DOMAIN: 'mermaid.live'
2525
MERMAID_ANALYTICS_URL: 'https://p.mermaid.live'
26+
MERMAID_RENDERER_URL: 'https://mermaid.ink'
27+
MERMAID_KROKI_RENDERER_URL: 'https://kroki.io'
28+
MERMAID_IS_ENABLED_MERMAID_CHART_LINKS: 'true'
2629
run: |
2730
export DEPLOY=true
2831
[ "$GITHUB_EVENT_NAME" != "pull_request" ] && rm -rf docs/_app/

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ yarn-error.log
1111
/snapshots.js
1212
/cypress/downloads
1313
/cypress/videos
14-
/cypress/screenshots
14+
/cypress/screenshots

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ARG MERMAID_RENDERER_URL
1818
ARG MERMAID_KROKI_RENDERER_URL
1919
ARG MERMAID_ANALYTICS_URL
2020
ARG MERMAID_DOMAIN
21+
ARG MERMAID_IS_ENABLED_MERMAID_CHART_LINKS
2122

2223
COPY . ./
2324

README.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,37 @@ docker run --platform linux/amd64 --publish 8000:8080 ghcr.io/mermaid-js/mermaid
2929

3030
### To configure renderer URL
3131

32-
When building set the MERMAID_RENDERER_URL build argument to the rendering service.
33-
Default is `https://mermaid.ink`
32+
When building set the MERMAID_RENDERER_URL build argument to the rendering
33+
service.
34+
Example:
35+
Default is`https://mermaid.ink`.
36+
Set to empty string to disable PNG and SVG links under Actions
3437

3538
### To configure Kroki Instance URL
3639

37-
When building set the MERMAID_KROKI_RENDERER_URL build argument to your Kroki instance.
40+
When building set the MERMAID_KROKI_RENDERER_URL build argument to your Kroki
41+
instance.
3842
Default is `https://kroki.io`
43+
Set to empty string to disable Kroki link under Actions
3944

4045
### To configure Analytics
4146

4247
When building set the MERMAID_ANALYTICS_URL build argument to your plausible instance, and MERMAID_DOMAIN to your domain.
4348

4449
Default is empty, disabling analytics.
4550

51+
### To enable Mermaid Chart links and promotion
52+
53+
When building set the MERMAID_IS_ENABLED_MERMAID_CHART_LINKS build argument to `true`
54+
55+
Default is empty, disabling button to save to Mermaid Chart and promotional banner.
56+
57+
### To update the Security modal
58+
59+
The modal shown on clicking the security link assumes analytics, renderer, Kroki
60+
and Mermaid chart are enabled. You can update it by modifying `Privacy.svelte`
61+
if you wish.
62+
4663
### Development
4764

4865
```bash

netlify.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[build.environment]
22
MERMAID_ANALYTICS_URL = 'https://p.mermaid.live'
33
MERMAID_DOMAIN = 'mermaid.live'
4+
MERMAID_RENDERER_URL = 'https://mermaid.ink'
5+
MERMAID_KROKI_RENDERER_URL = 'https://kroki.io'
6+
MERMAID_IS_ENABLED_MERMAID_CHART_LINKS ='true'

src/env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interface ImportMetaEnv {
55
readonly MERMAID_KROKI_RENDERER_URL?: string;
66
readonly MERMAID_ANALYTICS_URL?: string;
77
readonly MERMAID_DOMAIN?: string;
8+
readonly MERMAID_IS_ENABLED_MERMAID_CHART_LINKS?: string;
89
// more env variables...
910
}
1011

src/lib/components/Actions.svelte

+29-23
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,25 @@ ${svgString}`);
197197
<button id="downloadSVG" class="action-btn flex-grow" on:click={onDownloadSVG}>
198198
<i class="fas fa-download mr-2" /> SVG
199199
</button>
200-
<a target="_blank" rel="noreferrer" class="flex-grow" href={iUrl}>
201-
<button class="action-btn w-full">
202-
<i class="fas fa-external-link-alt mr-2" /> PNG
203-
</button>
204-
</a>
205-
<a target="_blank" rel="noreferrer" class="flex-grow" href={svgUrl}>
206-
<button class="action-btn w-full">
207-
<i class="fas fa-external-link-alt mr-2" /> SVG
208-
</button>
209-
</a>
210-
<a target="_blank" rel="noreferrer" class="flex-grow" href={krokiUrl}>
211-
<button class="action-btn w-full">
212-
<i class="fas fa-external-link-alt mr-2" /> Kroki
213-
</button>
214-
</a>
200+
{#if rendererUrl}
201+
<a target="_blank" rel="noreferrer" class="flex-grow" href={iUrl}>
202+
<button class="action-btn w-full">
203+
<i class="fas fa-external-link-alt mr-2" /> PNG
204+
</button>
205+
</a>
206+
<a target="_blank" rel="noreferrer" class="flex-grow" href={svgUrl}>
207+
<button class="action-btn w-full">
208+
<i class="fas fa-external-link-alt mr-2" /> SVG
209+
</button>
210+
</a>
211+
{/if}
212+
{#if krokiRendererUrl}
213+
<a target="_blank" rel="noreferrer" class="flex-grow" href={krokiUrl}>
214+
<button class="action-btn w-full">
215+
<i class="fas fa-external-link-alt mr-2" /> Kroki
216+
</button>
217+
</a>
218+
{/if}
215219

216220
<div class="flex items-center gap-2">
217221
PNG size
@@ -238,14 +242,16 @@ ${svgString}`);
238242
{/if}
239243
</div>
240244

241-
<div class="flex w-full items-center gap-2">
242-
<input class="input" id="markdown" type="text" value={mdCode} on:click={onCopyMarkdown} />
243-
<label for="markdown">
244-
<button class="btn btn-primary btn-md flex-auto" on:click={onCopyMarkdown}>
245-
Copy Markdown
246-
</button>
247-
</label>
248-
</div>
245+
{#if rendererUrl}
246+
<div class="flex w-full items-center gap-2">
247+
<input class="input" id="markdown" type="text" value={mdCode} on:click={onCopyMarkdown} />
248+
<label for="markdown">
249+
<button class="btn btn-primary btn-md flex-auto" on:click={onCopyMarkdown}>
250+
Copy Markdown
251+
</button>
252+
</label>
253+
</div>
254+
{/if}
249255

250256
<div class="flex w-full items-center gap-2">
251257
<input

src/lib/components/Navbar.svelte

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
</script>
88

99
<script lang="ts">
10+
import { env } from '$lib/util/env';
1011
import Theme from './Theme.svelte';
1112
import { dismissPromotion, getActivePromotion } from '$lib/util/promos/promo';
1213
import Privacy from './Privacy.svelte';
14+
15+
const { isEnabledMermaidChartLinks } = env;
16+
1317
let isMenuOpen = false;
1418
1519
function toggleMenu() {
@@ -22,7 +26,8 @@
2226
icon?: string;
2327
img?: string;
2428
}
25-
const links: Link[] = [
29+
30+
let links: Link[] = [
2631
{
2732
title: 'Documentation',
2833
href: 'https://mermaid.js.org/intro/getting-started.html'
@@ -42,13 +47,16 @@
4247
{
4348
href: 'https://github.com/mermaid-js/mermaid-live-editor',
4449
icon: 'fab fa-github fa-lg'
45-
},
46-
{
47-
href: 'https://mermaidchart.com',
48-
img: './mermaidchart-logo.svg'
4950
}
5051
];
5152
53+
if (isEnabledMermaidChartLinks) {
54+
links.push({
55+
href: 'https://mermaidchart.com',
56+
img: './mermaidchart-logo.svg'
57+
});
58+
}
59+
5260
let activePromotion = getActivePromotion();
5361
5462
const trackBannerClick = () => {

src/lib/util/env.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const env = {
2-
rendererUrl: import.meta.env.MERMAID_RENDERER_URL ?? 'https://mermaid.ink',
3-
krokiRendererUrl: import.meta.env.MERMAID_KROKI_RENDERER_URL ?? 'https://kroki.io',
2+
rendererUrl: import.meta.env.MERMAID_RENDERER_URL ?? '',
3+
krokiRendererUrl: import.meta.env.MERMAID_KROKI_RENDERER_URL ?? '',
44
analyticsUrl: import.meta.env.MERMAID_ANALYTICS_URL ?? '',
5-
domain: import.meta.env.MERMAID_DOMAIN ?? 'mermaid.live'
5+
domain: import.meta.env.MERMAID_DOMAIN ?? '',
6+
isEnabledMermaidChartLinks: import.meta.env.MERMAID_IS_ENABLED_MERMAID_CHART_LINKS == 'true'
67
} as const;

src/lib/util/promos/promo.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { writable, type Writable, get } from 'svelte/store';
22
import { persist, localStorage } from '../persist';
33
import August2024 from './August2024.svelte';
4+
import { env } from '$lib/util/env';
45

56
interface Promotion {
67
id: string;
@@ -35,6 +36,10 @@ const dismissedPromotionsStore: Writable<string[]> = persist(
3536
);
3637

3738
export const getActivePromotion = (): Promotion | undefined => {
39+
if (!env.isEnabledMermaidChartLinks) {
40+
return;
41+
}
42+
3843
const dismissedPromotions = get(dismissedPromotionsStore);
3944
const now = new Date();
4045
return promotions

src/routes/edit/+page.svelte

+10-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Preset from '$lib/components/Preset.svelte';
1010
import View from '$lib/components/View.svelte';
1111
import type { DocumentationConfig, EditorMode, Tab, ValidatedState } from '$lib/types';
12+
import { env } from '$lib/util/env';
1213
import { inputStateStore, stateStore, updateCodeStore } from '$lib/util/state';
1314
import { cmdKey, initHandler, syncDiagram } from '$lib/util/util';
1415
import { onMount } from 'svelte';
@@ -215,13 +216,15 @@
215216
target="_blank"
216217
class="btn btn-secondary btn-xs gap-1"
217218
title="View diagram in new page"><i class="fas fa-external-link-alt" />Full screen</a>
218-
<a
219-
href={`${MCBaseURL}/app/plugin/save?state=${$stateStore.serialized}`}
220-
target="_blank"
221-
class="btn btn-secondary btn-xs gap-1 bg-[#FF3570]"
222-
title="Save diagram in Mermaid Chart"
223-
><img src="./mermaidchart-logo.svg" class="h-5 w-5" alt="Mermaid chart logo" />Save to
224-
Mermaid Chart</a>
219+
{#if env.isEnabledMermaidChartLinks}
220+
<a
221+
href={`${MCBaseURL}/app/plugin/save?state=${$stateStore.serialized}`}
222+
target="_blank"
223+
class="btn btn-secondary btn-xs gap-1 bg-[#FF3570]"
224+
title="Save diagram in Mermaid Chart"
225+
><img src="./mermaidchart-logo.svg" class="h-5 w-5" alt="Mermaid chart logo" />Save to
226+
Mermaid Chart</a>
227+
{/if}
225228
</div>
226229

227230
<div class="flex-1 overflow-auto">

0 commit comments

Comments
 (0)