From fa9e56007f66f4cf30795f4b901ed053eec3bd41 Mon Sep 17 00:00:00 2001
From: Alexander Bilz <mail@alexbilz.com>
Date: Tue, 21 Jul 2020 17:34:52 +0000
Subject: [PATCH] ⌨ Added abilitiy to include remote JavaScript files

---
 layouts/partials/head.html |   16 ++++++++++------
 README.md                  |   10 ++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index f6d15ed..ae3fd56 100644
--- a/README.md
+++ b/README.md
@@ -150,6 +150,16 @@
 ```
 `hello.js` and `world.js` will be bundled into a `custom.min.js`.
 
+You can also include links to remote javascript files (hosted on CDNs for example). But be aware, that integrity settings and minification won't be applied. Further make sure to adjust your CSP. You can load a remote script like this:
+```toml
+[params]
+customJs = ["http://cdn.exmple.org/fancyscript.js"]
+```
+Both approaches can even be mixed:
+```toml
+[params]
+customJs = ["https://cdn.exmple.org/fancyscript.js", "js/world.js"]
+```
 ### Content Security Policy
 The theme is compliant with most strict CSP policies out of the box. A sample CSP for an Anatole-based site would look something like this:
 
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index eee232a..ae99a4a 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -28,12 +28,16 @@
     
     {{- $js := "" -}}
     {{- range .Site.Params.customJs -}}
-      {{- $customJS := resources.Get . -}}
-      {{- if $customJS -}}
-        {{- if eq $js "" -}}
-          {{- $js = $customJS -}}
-        {{- else -}}
-          {{- $js = slice $js $customJS | resources.Concat "js/custom.js" -}}
+      {{- if or (in . "http://") (in . "https://")  -}}
+      <script src="{{ . | relURL }}"></script>
+      {{- else -}}
+        {{- $customJS := resources.Get . -}}
+        {{- if $customJS -}}
+          {{- if eq $js "" -}}
+            {{- $js = $customJS -}}
+          {{- else -}}
+            {{- $js = slice $js $customJS | resources.Concat "js/custom.js" -}}
+          {{- end -}}
         {{- end -}}
       {{- end -}}
     {{- end -}}

--
Gitblit v1.10.0