From 0af36f12b74a6d95cdbb05aef329da952bac1784 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Wed, 9 Nov 2022 22:38:21 +0530 Subject: [PATCH] feat: Switch CDN --- docs/README.md | 2 +- docs/index.html | 8 ++++---- docs/n00b-gettingStarted.md | 4 ++-- docs/usage.md | 4 ++-- packages/mermaid/src/docs.mts | 12 +++++++----- packages/mermaid/src/docs/README.md | 2 +- packages/mermaid/src/docs/index.html | 8 ++++---- packages/mermaid/src/docs/n00b-gettingStarted.md | 4 ++-- packages/mermaid/src/docs/usage.md | 4 ++-- 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/docs/README.md b/docs/README.md index 69acccb499..0a1691179d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -275,7 +275,7 @@ To Deploy Mermaid: ```html ``` diff --git a/docs/index.html b/docs/index.html index 70a75548e3..7adf7225ef 100644 --- a/docs/index.html +++ b/docs/index.html @@ -49,8 +49,8 @@
@@ -144,7 +144,7 @@ Rendering in Mermaid is initialized by `mermaid.initialize()` call. You can plac diff --git a/docs/usage.md b/docs/usage.md index 0c8d103a89..1f22963249 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -58,7 +58,7 @@ Example: ```html ``` @@ -81,7 +81,7 @@ Example: B-->D(fa:fa-spinner); diff --git a/packages/mermaid/src/docs.mts b/packages/mermaid/src/docs.mts index f618165a31..e89e933a4c 100644 --- a/packages/mermaid/src/docs.mts +++ b/packages/mermaid/src/docs.mts @@ -44,6 +44,7 @@ import flatmap from 'unist-util-flatmap'; const MERMAID_MAJOR_VERSION = ( JSON.parse(readFileSync('packages/mermaid/package.json', 'utf8')).version as string ).split('.')[0]; +const CDN_URL = 'https://unpkg.com'; // https://cdn.jsdelivr.net/npm // These paths are from the root of the mono-repo, not from the // mermaid sub-directory @@ -135,6 +136,9 @@ const readSyncedUTF8file = (filename: string): string => { return readFileSync(filename, 'utf8'); }; +const injectPlaceholders = (text: string): string => + text.replace(//g, MERMAID_MAJOR_VERSION).replace(//g, CDN_URL); + /** * Transform a markdown file and write the transformed file to the directory for published * documentation @@ -148,7 +152,8 @@ const readSyncedUTF8file = (filename: string): string => { * @param file {string} name of the file that will be verified */ const transformMarkdown = (file: string) => { - const doc = readSyncedUTF8file(file).replace(//g, MERMAID_MAJOR_VERSION); + const doc = injectPlaceholders(readSyncedUTF8file(file)); + const ast: Root = remark.parse(doc); const out = flatmap(ast, (c: Code) => { if (c.type !== 'code') { @@ -189,10 +194,7 @@ const transformHtml = (filename: string) => { * @returns {string} The contents of the file with the comment inserted */ const insertAutoGeneratedComment = (fileName: string): string => { - const fileContents = readSyncedUTF8file(fileName).replace( - //g, - MERMAID_MAJOR_VERSION - ); + const fileContents = injectPlaceholders(readSyncedUTF8file(fileName)); const jsdom = new JSDOM(fileContents); const htmlDoc = jsdom.window.document; const autoGeneratedComment = jsdom.window.document.createComment(AUTOGENERATED_TEXT); diff --git a/packages/mermaid/src/docs/README.md b/packages/mermaid/src/docs/README.md index 880e40b43d..b0435479f5 100644 --- a/packages/mermaid/src/docs/README.md +++ b/packages/mermaid/src/docs/README.md @@ -191,7 +191,7 @@ To Deploy Mermaid: ```html ``` diff --git a/packages/mermaid/src/docs/index.html b/packages/mermaid/src/docs/index.html index ce4cd2e0e2..81eeafb2a9 100644 --- a/packages/mermaid/src/docs/index.html +++ b/packages/mermaid/src/docs/index.html @@ -49,8 +49,8 @@
@@ -142,7 +142,7 @@ Rendering in Mermaid is initialized by `mermaid.initialize()` call. You can plac diff --git a/packages/mermaid/src/docs/usage.md b/packages/mermaid/src/docs/usage.md index 00c44c0d9c..be2b94f728 100644 --- a/packages/mermaid/src/docs/usage.md +++ b/packages/mermaid/src/docs/usage.md @@ -58,7 +58,7 @@ Example: ```html ``` @@ -81,7 +81,7 @@ Example: B-->D(fa:fa-spinner);