Skip to content

Commit

Permalink
fix: mermaid-js#381 URL mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Sep 22, 2021
1 parent f76c89f commit dfe32b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/lib/components/actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { browser } from '$app/env';
import Card from '$lib/components/card/card.svelte';
import type { State } from '$lib/types';
import { codeStore } from '$lib/util/state';
import { base64State, codeStore } from '$lib/util/state';
import { toBase64 } from 'js-base64';
import moment from 'moment';
Expand Down Expand Up @@ -137,15 +136,15 @@
if (browser && ['mermaid.live', 'netlify'].some((path) => window.location.host.includes(path))) {
isNetlify = true;
}
codeStore.subscribe((state: State) => {
const stateCopy = JSON.parse(JSON.stringify(state));
base64State.subscribe((encodedState: string) => {
const stateCopy = JSON.parse(JSON.stringify($codeStore));
if (typeof stateCopy.mermaid === 'string') {
stateCopy.mermaid = JSON.parse(stateCopy.mermaid);
}
const b64Code = toBase64(JSON.stringify(stateCopy), true);
iUrl = `https://mermaid.ink/img/${b64Code}`;
svgUrl = `https://mermaid.ink/svg/${b64Code}`;
mdCode = `[![](${iUrl})](${window.location.protocol}//${window.location.host}${window.location.pathname}#${window.location.hash})`;
mdCode = `[![](${iUrl})](${window.location.protocol}//${window.location.host}${window.location.pathname}#${encodedState})`;
});
</script>

Expand Down
3 changes: 2 additions & 1 deletion src/lib/util/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { writable, get, derived } from 'svelte/store';
import type { Readable } from 'svelte/store';
import { toBase64, fromBase64 } from 'js-base64';
import { persist, localStorage } from '@macfja/svelte-persistent-store';
import type { State } from '$lib/types';
Expand All @@ -25,7 +26,7 @@ export const defaultState: State = {
};

export const codeStore = persist(writable(defaultState), localStorage(), 'codeStore');
export const base64State = derived([codeStore], ([code], set) => {
export const base64State: Readable<string> = derived([codeStore], ([code], set) => {
set(toBase64(JSON.stringify(code), true));
});

Expand Down

0 comments on commit dfe32b9

Please sign in to comment.