Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch CDN to unpkg.com #3777

Merged
merged 1 commit into from Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Expand Up @@ -275,7 +275,7 @@ To Deploy Mermaid:

```html
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
import mermaid from 'https://unpkg.com/mermaid@9/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
```
Expand Down
8 changes: 4 additions & 4 deletions docs/index.html
Expand Up @@ -49,8 +49,8 @@
<body>
<div id="app"></div>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9.2.2/dist/mermaid.esm.min.mjs';
import mindmap from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-mindmap@9.2.2/dist/mermaid-mindmap.esm.mjs';
import mermaid from 'https://unpkg.com/mermaid@9/dist/mermaid.esm.min.mjs';
import mindmap from 'https://unpkg.com/@mermaid-js/mermaid-mindmap@9/dist/mermaid-mindmap.esm.min.mjs';
await mermaid.registerExternalDiagrams([mindmap]);

window.mermaid = mermaid;
Expand Down Expand Up @@ -145,8 +145,8 @@
return editHtml + html;
});
// Invoked on each page load after new HTML has been appended to the DOM
hook.doneEach(function () {
window.mermaid.init();
hook.doneEach(async function () {
await mermaid.init();
});

hook.afterEach(function (html, next) {
Expand Down
4 changes: 2 additions & 2 deletions docs/n00b-gettingStarted.md
Expand Up @@ -104,7 +104,7 @@ b. The importing of mermaid library through the `mermaid.esm.js` or `mermaid.esm
```html
<body>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
import mermaid from 'https://unpkg.com/mermaid@9/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
</body>
Expand Down Expand Up @@ -144,7 +144,7 @@ Rendering in Mermaid is initialized by `mermaid.initialize()` call. You can plac
</pre>

<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
import mermaid from 'https://unpkg.com/mermaid@9/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.md
Expand Up @@ -58,7 +58,7 @@ Example:

```html
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
import mermaid from 'https://unpkg.com/mermaid@9/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
```
Expand All @@ -81,7 +81,7 @@ Example:
B-->D(fa:fa-spinner);
</pre>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
import mermaid from 'https://unpkg.com/mermaid@9/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
</body>
Expand Down
12 changes: 7 additions & 5 deletions packages/mermaid/src/docs.mts
Expand Up @@ -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
Expand Down Expand Up @@ -135,6 +136,9 @@ const readSyncedUTF8file = (filename: string): string => {
return readFileSync(filename, 'utf8');
};

const injectPlaceholders = (text: string): string =>
text.replace(/<MERMAID_VERSION>/g, MERMAID_MAJOR_VERSION).replace(/<CDN_URL>/g, CDN_URL);

/**
* Transform a markdown file and write the transformed file to the directory for published
* documentation
Expand All @@ -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(/<MERMAID_VERSION>/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') {
Expand Down Expand Up @@ -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(
/<MERMAID_VERSION>/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);
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/docs/README.md
Expand Up @@ -191,7 +191,7 @@ To Deploy Mermaid:

```html
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
import mermaid from '<CDN_URL>/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
```
Expand Down
8 changes: 4 additions & 4 deletions packages/mermaid/src/docs/index.html
Expand Up @@ -49,8 +49,8 @@
<body>
<div id="app"></div>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
import mindmap from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-mindmap@<MERMAID_VERSION>/dist/mermaid-mindmap.esm.mjs';
import mermaid from '<CDN_URL>/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
import mindmap from '<CDN_URL>/@mermaid-js/mermaid-mindmap@<MERMAID_VERSION>/dist/mermaid-mindmap.esm.min.mjs';
await mermaid.registerExternalDiagrams([mindmap]);

window.mermaid = mermaid;
Expand Down Expand Up @@ -145,8 +145,8 @@
return editHtml + html;
});
// Invoked on each page load after new HTML has been appended to the DOM
hook.doneEach(function () {
window.mermaid.init();
hook.doneEach(async function () {
await mermaid.init();
});

hook.afterEach(function (html, next) {
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/docs/n00b-gettingStarted.md
Expand Up @@ -102,7 +102,7 @@ b. The importing of mermaid library through the `mermaid.esm.js` or `mermaid.esm
```html
<body>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
import mermaid from '<CDN_URL>/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
</body>
Expand Down Expand Up @@ -142,7 +142,7 @@ Rendering in Mermaid is initialized by `mermaid.initialize()` call. You can plac
</pre>

<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
import mermaid from '<CDN_URL>/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/docs/usage.md
Expand Up @@ -58,7 +58,7 @@ Example:

```html
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
import mermaid from '<CDN_URL>/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
```
Expand All @@ -81,7 +81,7 @@ Example:
B-->D(fa:fa-spinner);
</pre>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
import mermaid from '<CDN_URL>/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
</body>
Expand Down