From de3f78c9c41e999d9072ae6ed93d3e49127d2aeb Mon Sep 17 00:00:00 2001
From: Alexander Bilz <mail@alexbilz.com>
Date: Tue, 05 Jan 2021 10:21:05 +0000
Subject: [PATCH] Merge branch 'master' into date-improvements

---
 exampleSite/config.toml                         |   11 +
 /dev/null                                       |   24 ----
 layouts/_default/baseof.html                    |    3 
 layouts/partials/sidebar.html                   |    2 
 assets/js/anatole-header.js                     |   54 ----------
 i18n/zh-cn.toml                                 |   24 ++++
 layouts/partials/analytics/simpleanalytics.html |    7 +
 assets/js/anatole-theme-switcher.js             |   51 ++++++++++
 layouts/partials/navbar.html                    |   12 +-
 layouts/partials/head.html                      |   18 ++
 README.md                                       |   24 ++++
 i18n/pt-br.toml                                 |   24 ++++
 12 files changed, 163 insertions(+), 91 deletions(-)

diff --git a/README.md b/README.md
index 6f7756a..621fe74 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,7 @@
 - Multilingual
 - 100⁄100 Google Lighthouse score
 - Google Analytics (optional)
+- SimpleAnalytics (optional)
 - Comments powered by Disqus (optional)
 - Katex support (optional)
 - Formspree Contact Form (optional)
@@ -71,6 +72,12 @@
 
 Add you own favicon in `static/favicons/favicon.ico`.
 
+### Copyright
+By default the copyright, will show the current year, but you can change this by configuring the `copyright` parameter.
+```toml
+copyright = "2020-2021"
+```
+
 ### Navigation items
 
 Non-content entries can be added right from the `config.toml` file.
@@ -108,6 +115,13 @@
 displayMode = "dark"
 ```
 
+### Disable Theme Switcher
+You can easily disable the theme switcher from the `config.toml`. All you have to do is to set the parameter `disableThemeSwitcher` to `true`.
+```toml
+[params]
+disableThemeSwitcher = true # Theme switcher is enabled by default
+```
+
 ### Disable Animations
 You can easily disable the animations from the `config.toml`. All you have to do is to set the parameter `doNotLoadAnimations` to `true`.
 ```toml
@@ -205,6 +219,16 @@
 googleAnalytics = "UA-123-45"
 ```
 
+### Simple Analytics
+
+To use Simple Analytics, it has to be enabled by setting the parameter to true. If you are using a custom subdomain to evade Adblockers, then specify the URL without a trailing slash.
+
+```toml
+[params.simpleAnalytics]
+enable = true
+# customurl = "https://analytics.example.com"
+```
+
 ### Google Site Verification
 
 To use Google Site Verification, add the following line to the `[params]`:
diff --git a/assets/js/anatole-header.js b/assets/js/anatole-header.js
index 901fc0f..0bae781 100644
--- a/assets/js/anatole-header.js
+++ b/assets/js/anatole-header.js
@@ -1,53 +1,3 @@
-// initialize default value
-function getTheme() {
-    return localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
-}
-
-function setTheme(style) {
-    document.documentElement.setAttribute('data-theme', style);
-    localStorage.setItem('theme', style);
-}
-
-function init() {
-    // initialize default value
-    var theme = getTheme();
-
-    // check if a prefered color theme is set for users that have never been to our site
-    const userPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
-    if (theme === null) {
-        if (userPrefersDark) {
-            setTheme('dark');
-        } else if (!document.documentElement.getAttribute('data-theme')) {
-            setTheme('light');
-        } else {
-            setTheme(document.documentElement.getAttribute('data-theme'));
-        }
-    } else {
-        // load a stored theme
-        if (theme == 'light') {
-            document.documentElement.setAttribute('data-theme', 'light');
-        } else {
-            document.documentElement.setAttribute('data-theme', 'dark');
-        }
-    }
-}
-
-
-// switch themes
-function switchTheme(e) {
-    var theme = getTheme();
-    if (theme == 'light') {
-        setTheme('dark');
-    } else {
-        setTheme('light');
-    }
-}
-
-document.addEventListener('DOMContentLoaded', function () {
-    var themeSwitcher = document.querySelector('.theme-switch');
-    themeSwitcher.addEventListener('click', switchTheme, false);
-}, false);
-
 document.addEventListener("DOMContentLoaded", function () {
 // Get all "navbar-burger" elements
     var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll(".navbar-burger"), 0);
@@ -63,6 +13,4 @@
             });
         });
     }
-});
-
-init();
+});
\ No newline at end of file
diff --git a/assets/js/anatole-theme-switcher.js b/assets/js/anatole-theme-switcher.js
new file mode 100644
index 0000000..ac82793
--- /dev/null
+++ b/assets/js/anatole-theme-switcher.js
@@ -0,0 +1,51 @@
+// initialize default value
+function getTheme() {
+    return localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
+}
+
+function setTheme(style) {
+    document.documentElement.setAttribute('data-theme', style);
+    localStorage.setItem('theme', style);
+}
+
+function init() {
+    // initialize default value
+    const theme = getTheme();
+
+    // check if a preferred color theme is set for users that have never been to our site
+    const userPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
+    if (theme === null) {
+        if (userPrefersDark) {
+            setTheme('dark');
+        } else if (!document.documentElement.getAttribute('data-theme')) {
+            setTheme('light');
+        } else {
+            setTheme(document.documentElement.getAttribute('data-theme'));
+        }
+    } else {
+        // load a stored theme
+        if (theme === 'light') {
+            document.documentElement.setAttribute('data-theme', 'light');
+        } else {
+            document.documentElement.setAttribute('data-theme', 'dark');
+        }
+    }
+}
+
+
+// switch themes
+function switchTheme() {
+    const theme = getTheme();
+    if (theme === 'light') {
+        setTheme('dark');
+    } else {
+        setTheme('light');
+    }
+}
+
+document.addEventListener('DOMContentLoaded', function () {
+    const themeSwitcher = document.querySelector('.theme-switch');
+    themeSwitcher.addEventListener('click', switchTheme, false);
+}, false);
+
+init();
diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index fcb66b2..4782677 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -21,6 +21,7 @@
 [params]
 title = "I'm Jane Doe"
 author = "Jane Doe"
+#copyright = "2020-2021"
 description = "Call me Jane"
 profilePicture = "images/profile.jpg"
 keywords = ""
@@ -36,11 +37,13 @@
 #contactFormAction = "https://formspree.io/f/your-form-hash-here"
 # Google Site Verify
 #googleSiteVerify = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
+# indexDateFormat = "Mon, Jan 2, 2006"
+# listDateFormat = "Jan 2"
+# singleDateFormat = "Mon, Jan 2, 2006"
 
-indexDateFormat = "Mon, Jan 2, 2006"
-listDateFormat = "Jan 2"
-singleDateFormat = "Mon, Jan 2, 2006"
-
+[params.simpleAnalytics]
+# enable = true
+# customurl = "https://analytics.example.com"
 
 ## Math settings
 [params.math]
diff --git a/i18n/pt-br.toml b/i18n/pt-br.toml
new file mode 100644
index 0000000..2456fa9
--- /dev/null
+++ b/i18n/pt-br.toml
@@ -0,0 +1,24 @@
+[category]
+other = "categoria"
+
+[tag]
+other = "etiqueta"
+
+[reading_time]
+one = "Tempo de leitura: 1 minuto"
+other = "Tempo de leitura: {{ .Count }} minutos"
+
+[page_not_found]
+other = "Página não encontrada"
+
+[page_does_not_exist]
+other = "Desculpa, esta página não existe."
+
+[head_back]
+other = "Retornar à <a href=\"{{ . }}\">página inicial</a>."
+
+[comments]
+other = "comentários"
+
+[send]
+other = "Enviar"
diff --git a/i18n/zh-cn.toml b/i18n/zh-cn.toml
new file mode 100755
index 0000000..62c1293
--- /dev/null
+++ b/i18n/zh-cn.toml
@@ -0,0 +1,24 @@
+[category]
+other = "分类"
+
+[tag]
+other = "标签"
+
+[reading_time]
+one = "阅读时间 1 分钟"
+other = "阅读时间 {{ .Count }} 分钟"
+
+[page_not_found]
+other = "页面未找到"
+
+[page_does_not_exist]
+other = "抱歉,此页面不存在"
+
+[head_back]
+other = "返回<a href=\"{{ . }}\">首页</a>."
+
+[comments]
+other = "评论"
+
+[send]
+other = "发送"
diff --git a/i18n/zh-zn.toml b/i18n/zh-zn.toml
deleted file mode 100644
index f9e60ce..0000000
--- a/i18n/zh-zn.toml
+++ /dev/null
@@ -1,24 +0,0 @@
-[category]
-other = "分类"
-
-[tag]
-other = "标签"
-
-[reading_time]
-one = "1分钟阅读时间"
-other = "{{ .Count }}分钟阅读时间"
-
-[page_not_found]
-other = "找不到页面"
-
-[page_does_not_exist]
-other = "此页面不存在"
-
-[head_back]
-other = "返回 <a href=\"{{ . }}\">主页面</a>."
-
-[comments]
-other = "注释"
-
-[send]
-other = "发送"
\ No newline at end of file
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 8542ce5..dc92dba 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -14,6 +14,9 @@
 </div>
 
 {{- partial "footer.html" . -}}
+{{- if (eq .Site.Params.simpleAnalytics.enable true) -}}
+    {{- partial "analytics/simpleanalytics.html" . -}}
+{{- end -}}
 </body>
 
 </html>
diff --git a/layouts/partials/analytics/simpleanalytics.html b/layouts/partials/analytics/simpleanalytics.html
new file mode 100644
index 0000000..1d6c745
--- /dev/null
+++ b/layouts/partials/analytics/simpleanalytics.html
@@ -0,0 +1,7 @@
+{{ with .Site.Params.simpleAnalytics.customUrl }}
+<script async defer src="{{ . | relURL }}/latest.js"></script>
+<noscript><img src="{{ . | relURL }}/noscript.gif" alt=""/></noscript>
+{{ else }}
+<script async defer src=" https://scripts.simpleanalyticscdn.com/latest.js"></script>
+<noscript><img src="https://queue.simpleanalyticscdn.com/noscript.gif" alt=""/></noscript>
+{{ end }}
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index c09cf55..62bc8e7 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -51,13 +51,23 @@
     {{ end -}}
 
     <!-- JavaScript -->
-    {{ $anatole := resources.Get "js/anatole-header.js" }}
-    {{ $secureJS := $anatole |  resources.Minify | resources.Fingerprint }}
+    {{ $anatoleHeader := resources.Get "js/anatole-header.js" }}
+    {{ $secureHeaderJS := $anatoleHeader |  resources.Minify | resources.Fingerprint }}
     <script type="text/javascript"
-            src="{{ $secureJS.Permalink }}"
-            integrity="{{ $secureJS.Data.Integrity }}"
+            src="{{ $secureHeaderJS.Permalink }}"
+            integrity="{{ $secureHeaderJS.Data.Integrity }}"
             crossorigin="anonymous"></script>
 
+
+    {{ if not .Site.Params.disableThemeSwitcher }}
+        {{ $anatoleThemeSwitcher := resources.Get "js/anatole-theme-switcher.js" }}
+        {{ $secureThemeSwitcherJS := $anatoleThemeSwitcher |  resources.Minify | resources.Fingerprint }}
+        <script type="text/javascript"
+                src="{{ $secureThemeSwitcherJS.Permalink }}"
+                integrity="{{ $secureThemeSwitcherJS.Data.Integrity }}"
+                crossorigin="anonymous"></script>
+    {{ end }}
+
     {{- $js := "" -}}
     {{- range .Site.Params.customJs -}}
         {{- if or (in . "http://") (in . "https://") -}}
diff --git a/layouts/partials/navbar.html b/layouts/partials/navbar.html
index b35cbf5..9c4c28e 100644
--- a/layouts/partials/navbar.html
+++ b/layouts/partials/navbar.html
@@ -23,10 +23,12 @@
                 </li>
             {{ end }}
         {{ end }}
-        <li class="theme-switch-item">
-            <a class="theme-switch" title="Switch Theme">
-                <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
-            </a>
-        </li>
+        {{ if not .Site.Params.disableThemeSwitcher }}
+            <li class="theme-switch-item">
+                <a class="theme-switch" title="Switch Theme">
+                    <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
+                </a>
+            </li>
+        {{ end }}
     </ul>
 </div>
diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html
index 8595ef3..22afa5d 100644
--- a/layouts/partials/sidebar.html
+++ b/layouts/partials/sidebar.html
@@ -18,6 +18,6 @@
         {{ end }}
     </ul>
     <div class="footer">
-        <div class="by_farbox">&copy; {{ .Site.Params.author }} {{ now.Format "2006"}} </div>
+        <div class="by_farbox">&copy; {{ .Site.Params.author }} {{ if isset .Site.Params "copyright" }} {{ .Site.Params.copyright }} {{ else }} {{ now.Format "2006"}} {{end}}</div>
     </div>
 </div>

--
Gitblit v1.10.0