From a8504b8cc490b30a35390573d01a35ad26ea8893 Mon Sep 17 00:00:00 2001 From: Klemek Date: Wed, 17 Jul 2019 19:21:24 +0200 Subject: [PATCH] [skip CI]smart github CDN with custom script --- build_docs.sh | 6 ----- docs/github-cdn.js | 30 ++++++++++++++++++++++++ docs/index.html | 57 +++++++++++++++++++++++----------------------- 3 files changed, 59 insertions(+), 34 deletions(-) delete mode 100755 build_docs.sh create mode 100644 docs/github-cdn.js diff --git a/build_docs.sh b/build_docs.sh deleted file mode 100755 index e507a8d..0000000 --- a/build_docs.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -# temporary file - -npm run prepublishOnly -cp dist/*.min.js docs \ No newline at end of file diff --git a/docs/github-cdn.js b/docs/github-cdn.js new file mode 100644 index 0000000..59304a4 --- /dev/null +++ b/docs/github-cdn.js @@ -0,0 +1,30 @@ +const github = (repo) => { + const self = { + loadScript: (file) => new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.open('GET', `https://raw.githubusercontent.com/${repo}/master/${file}`); + xhr.onload = function () { + if (xhr.status === 200) { + const u = URL.createObjectURL(new Blob([xhr.responseText], {type: 'text/javascript'})); + const s = document.createElement('script'); + s.src = u; + s.onload = resolve; + s.onerror = reject; + document.body.appendChild(s); + document.body.removeChild(s); + URL.revokeObjectURL(u); + } else + reject(); + }; + xhr.send(); + }), + loadScripts: (...files) => new Promise((resolve, reject) => { + if (!files || !files.length) + return resolve(); + self.loadScript(files.splice(0, 1)).then(() => { + self.loadScripts(...files).then(resolve); + }).catch(reject); + }) + }; + return self; +}; \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index d983892..13c32b5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,9 +4,8 @@ fa-diagrams example - - - + + @@ -49,34 +48,36 @@