From 43c00a38685cc0f10f083a0a150c5ee65c2fb84a Mon Sep 17 00:00:00 2001
From: Alexander Bilz <mail@alexbilz.com>
Date: Fri, 17 Jul 2020 18:33:01 +0000
Subject: [PATCH] 👷🏼‍♂️ Added more custom options

---
 exampleSite/config.toml    |    1 +
 layouts/partials/head.html |   28 +++++++++++++++++++++++++---
 README.md                  |   28 ++++++++++++++++++++++++++--
 3 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index afc32f6..f6d15ed 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@
 - MIT License
 - Fontawesome icons
 - Custom CSS (optional)
+- Custom JavaScript (optional)
 - Medium like zoom for images
 - Compliant to strict CSP
 - Uses Hugo pipes to process assets
@@ -120,11 +121,34 @@
 
 
 ### Custom CSS
-You can add your custom CSS files with the `customCss` parameter of the configuration file. Put your files into the `static/css` directory.
+You can add your custom CSS files with the `customCss` parameter of the configuration file. Put your files into the `assets/css` directory.
 
 ```toml
-customCss = ["css/custom1.css", "css/custom2.css"]
+customCss = ["css/custom.css", "css/styles.css"]
 ```
+On the user-side it will look like this:
+```text
+.
+└── assets
+    └── css
+        ├── custom.css
+        └── styles.css
+```
+### Custom JavaScript
+You can add your custom JS files with the `customJs` parameter of the configuration file. Put your files into the `assets/js` directory.
+```toml
+[params]
+customJs = ["js/hello.js", "js/world.js"]
+```
+On the user-side it will look like this:
+```text
+.
+└── assets
+    └── js
+        ├── hello.js
+        └── world.js
+```
+`hello.js` and `world.js` will be bundled into a `custom.min.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/exampleSite/config.toml b/exampleSite/config.toml
index c012183..8914c70 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -21,6 +21,7 @@
 keywords = ""
 favicon = "favicons/"
 customCss = []
+customJs = []
 mainSections = ["post"]
 images = ["images/site-feature-image.png"]
 
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index d03eec7..eee232a 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -6,9 +6,11 @@
     <meta name="description" content="{{ .Site.Params.description }}">
     {{ $style := resources.Get "css/style.css" | resources.Minify | resources.Fingerprint }}
     <link rel="stylesheet" href="{{ $style.Permalink }}" integrity="{{ $style.Data.Integrity }}" crossorigin="anonymous" type="text/css">
-    {{ range .Site.Params.customCss -}}
-    <link rel="stylesheet" href="{{ . | absURL }}" type="text/css">
-    {{- end }}
+    {{- $css := "" -}}
+    {{- range .Site.Params.customCss -}}
+    {{ $css := resources.Get . | minify | fingerprint }}
+    <link rel="stylesheet" href="{{ $css.Permalink }}" integrity="{{ $css.Data.Integrity }}" crossorigin="anonymous" type="text/css">
+    {{- end -}}
     <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
     <!-- Favicons -->
     <link rel="shortcut icon" href="{{ .Site.Params.favicon | absURL }}favicon.ico" type="image/x-icon">
@@ -22,5 +24,25 @@
     {{ $anatole := resources.Get "js/anatole-header.js" }}
     {{ $secureJS := $anatole |  resources.Minify | resources.Fingerprint }}
     <script type="text/javascript" src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}" crossorigin="anonymous"></script>
+    
+    
+    {{- $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" -}}
+        {{- end -}}
+      {{- end -}}
+    {{- end -}}
+    
+    {{- if ne $js "" -}}
+    {{- $secureJS := $js |  resources.Minify | resources.Fingerprint -}}
+    <script type="text/javascript" src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}" crossorigin="anonymous"></script>
+    {{- end -}}
+
+    <!-- Twitter Cards -->
     {{ template "_internal/twitter_cards.html" . }}
 </head>
\ No newline at end of file

--
Gitblit v1.10.0