mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Merge pull request #3777 from mermaid-js/sidv/fixCDN
Switch CDN to unpkg.com
This commit is contained in:
commit
dcab2c552f
@ -275,7 +275,7 @@ To Deploy Mermaid:
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
@ -49,8 +49,8 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9.2.2/dist/mermaid.esm.min.mjs';
|
import mermaid from 'https://unpkg.com/mermaid@9/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 mindmap from 'https://unpkg.com/@mermaid-js/mermaid-mindmap@9/dist/mermaid-mindmap.esm.min.mjs';
|
||||||
await mermaid.registerExternalDiagrams([mindmap]);
|
await mermaid.registerExternalDiagrams([mindmap]);
|
||||||
|
|
||||||
window.mermaid = mermaid;
|
window.mermaid = mermaid;
|
||||||
@ -145,8 +145,8 @@
|
|||||||
return editHtml + html;
|
return editHtml + html;
|
||||||
});
|
});
|
||||||
// Invoked on each page load after new HTML has been appended to the DOM
|
// Invoked on each page load after new HTML has been appended to the DOM
|
||||||
hook.doneEach(function () {
|
hook.doneEach(async function () {
|
||||||
window.mermaid.init();
|
await mermaid.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
hook.afterEach(function (html, next) {
|
hook.afterEach(function (html, next) {
|
||||||
|
@ -104,7 +104,7 @@ b. The importing of mermaid library through the `mermaid.esm.js` or `mermaid.esm
|
|||||||
```html
|
```html
|
||||||
<body>
|
<body>
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
@ -144,7 +144,7 @@ Rendering in Mermaid is initialized by `mermaid.initialize()` call. You can plac
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -58,7 +58,7 @@ Example:
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
@ -81,7 +81,7 @@ Example:
|
|||||||
B-->D(fa:fa-spinner);
|
B-->D(fa:fa-spinner);
|
||||||
</pre>
|
</pre>
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -44,6 +44,7 @@ import flatmap from 'unist-util-flatmap';
|
|||||||
const MERMAID_MAJOR_VERSION = (
|
const MERMAID_MAJOR_VERSION = (
|
||||||
JSON.parse(readFileSync('packages/mermaid/package.json', 'utf8')).version as string
|
JSON.parse(readFileSync('packages/mermaid/package.json', 'utf8')).version as string
|
||||||
).split('.')[0];
|
).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
|
// These paths are from the root of the mono-repo, not from the
|
||||||
// mermaid sub-directory
|
// mermaid sub-directory
|
||||||
@ -135,6 +136,9 @@ const readSyncedUTF8file = (filename: string): string => {
|
|||||||
return readFileSync(filename, 'utf8');
|
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
|
* Transform a markdown file and write the transformed file to the directory for published
|
||||||
* documentation
|
* documentation
|
||||||
@ -148,7 +152,8 @@ const readSyncedUTF8file = (filename: string): string => {
|
|||||||
* @param file {string} name of the file that will be verified
|
* @param file {string} name of the file that will be verified
|
||||||
*/
|
*/
|
||||||
const transformMarkdown = (file: string) => {
|
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 ast: Root = remark.parse(doc);
|
||||||
const out = flatmap(ast, (c: Code) => {
|
const out = flatmap(ast, (c: Code) => {
|
||||||
if (c.type !== 'code') {
|
if (c.type !== 'code') {
|
||||||
@ -189,10 +194,7 @@ const transformHtml = (filename: string) => {
|
|||||||
* @returns {string} The contents of the file with the comment inserted
|
* @returns {string} The contents of the file with the comment inserted
|
||||||
*/
|
*/
|
||||||
const insertAutoGeneratedComment = (fileName: string): string => {
|
const insertAutoGeneratedComment = (fileName: string): string => {
|
||||||
const fileContents = readSyncedUTF8file(fileName).replace(
|
const fileContents = injectPlaceholders(readSyncedUTF8file(fileName));
|
||||||
/<MERMAID_VERSION>/g,
|
|
||||||
MERMAID_MAJOR_VERSION
|
|
||||||
);
|
|
||||||
const jsdom = new JSDOM(fileContents);
|
const jsdom = new JSDOM(fileContents);
|
||||||
const htmlDoc = jsdom.window.document;
|
const htmlDoc = jsdom.window.document;
|
||||||
const autoGeneratedComment = jsdom.window.document.createComment(AUTOGENERATED_TEXT);
|
const autoGeneratedComment = jsdom.window.document.createComment(AUTOGENERATED_TEXT);
|
||||||
|
@ -191,7 +191,7 @@ To Deploy Mermaid:
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
@ -49,8 +49,8 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module">
|
<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';
|
||||||
import mindmap from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-mindmap@<MERMAID_VERSION>/dist/mermaid-mindmap.esm.mjs';
|
import mindmap from '<CDN_URL>/@mermaid-js/mermaid-mindmap@<MERMAID_VERSION>/dist/mermaid-mindmap.esm.min.mjs';
|
||||||
await mermaid.registerExternalDiagrams([mindmap]);
|
await mermaid.registerExternalDiagrams([mindmap]);
|
||||||
|
|
||||||
window.mermaid = mermaid;
|
window.mermaid = mermaid;
|
||||||
@ -145,8 +145,8 @@
|
|||||||
return editHtml + html;
|
return editHtml + html;
|
||||||
});
|
});
|
||||||
// Invoked on each page load after new HTML has been appended to the DOM
|
// Invoked on each page load after new HTML has been appended to the DOM
|
||||||
hook.doneEach(function () {
|
hook.doneEach(async function () {
|
||||||
window.mermaid.init();
|
await mermaid.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
hook.afterEach(function (html, next) {
|
hook.afterEach(function (html, next) {
|
||||||
|
@ -102,7 +102,7 @@ b. The importing of mermaid library through the `mermaid.esm.js` or `mermaid.esm
|
|||||||
```html
|
```html
|
||||||
<body>
|
<body>
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
@ -142,7 +142,7 @@ Rendering in Mermaid is initialized by `mermaid.initialize()` call. You can plac
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -58,7 +58,7 @@ Example:
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
@ -81,7 +81,7 @@ Example:
|
|||||||
B-->D(fa:fa-spinner);
|
B-->D(fa:fa-spinner);
|
||||||
</pre>
|
</pre>
|
||||||
<script type="module">
|
<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 });
|
mermaid.initialize({ startOnLoad: true });
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user