mirror of https://github.com/luizdepra/hugo-coder.git

Wil Kong
15.34.2023 4a6b8fd3551842e89dd15f8181056fe48a3b04f7
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
3 files modified
1 files added
22 ■■■■■ changed files
CONTRIBUTORS.md 1 ●●●● patch | view | raw | blame | history
exampleSite/config.toml 4 ●●●● patch | view | raw | blame | history
layouts/_default/baseof.html 6 ●●●● patch | view | raw | blame | history
layouts/partials/analytics/baidu.html 11 ●●●●● patch | view | raw | blame | history
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)
exampleSite/config.toml
@@ -66,6 +66,10 @@
# [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
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>
layouts/partials/analytics/baidu.html
New file
@@ -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 -->