Prechádzať zdrojové kódy

Add Baidu Analytics (#808)

### Prerequisites

Put an `x` into the box(es) that apply:

- [ ] This pull request fixes a bug.
- [x] This pull request adds a feature.
- [ ] This pull request introduces breaking change.

### Description

Add Baidu Analytics (<https://tongji.baidu.com/>) to the theme.

### Issues Resolved

List any existing issues this pull request resolves.

### Checklist

Put an `x` into the box(es) that apply:

#### General

- [x] Describe what changes are being made
- [x] Explain why and how the changes were necessary and implemented
respectively
- [ ] Reference issue with `#<ISSUE_NO>` if applicable

#### Resources

- [ ] If you have changed any SCSS code, run `make release` to
regenerate all CSS files

#### Contributors

- [x] Add yourself to `CONTRIBUTORS.md` if you aren't on it already
Wil Kong 2 rokov pred
rodič
commit
4a6b8fd355

+ 1 - 0
CONTRIBUTORS.md

@@ -129,3 +129,4 @@
 - [Jaroslaw Rozanski](https://jarekrozanski.eu)
 - [Easton Man](https://github.com/eastonman)
 - [Yiğit Altınay](https://altinay.xyz)
+- [Fei Kong](https://github.com/alpha0422)

+ 4 - 0
exampleSite/config.toml

@@ -66,6 +66,10 @@ customRemoteJS = []
 # [params.cloudflare]
 # token = "token"
 
+# If you want to use Baidu Analytics(https://tongji.baidu.com) for analytics, add this section
+# [params.baidu]
+# token = "token"
+
 # If you want to use Matomo(https://matomo.org) for analytics, add this section
 # [params.matomo]
 # siteID = "ABCDE" # Default value is "1", overwrite this if you are cloud-hosting

+ 5 - 1
layouts/_default/baseof.html

@@ -80,6 +80,10 @@
   {{- partial "analytics/cloudflare" . -}}
   {{ end }}
 
+  {{ if and .Site.Params.baidu .Site.Params.baidu.token }}
+  {{- partial "analytics/baidu" . -}}
+  {{ end }}
+
   {{ if and .Site.Params.wideAngleAnalytics .Site.Params.wideAngleAnalytics.siteID }}
   {{- partial "analytics/wideangle" . -}}
   {{ end }}
@@ -115,4 +119,4 @@
   {{- partial "body/extensions" . -}}
 </body>
 
-</html>
+</html>

+ 11 - 0
layouts/partials/analytics/baidu.html

@@ -0,0 +1,11 @@
+<!-- Baidu Analytics -->
+<script>
+var _hmt = _hmt || [];
+(function() {
+    var hm = document.createElement("script");
+    hm.src = "https://hm.baidu.com/hm.js?{{ $.Site.Params.baidu.token }}";
+    var s = document.getElementsByTagName("script")[0]; 
+    s.parentNode.insertBefore(hm, s);
+})();
+</script>
+<!-- End Baidu Web Analytics -->