Added Cloudflare WebAnalytics module

This commit is contained in:
Maxim Lebedev 2020-12-25 20:02:58 +05:00
parent d497ca7d70
commit e1af133748
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
4 changed files with 54 additions and 0 deletions

38
cloudflare/README.md Normal file
View File

@ -0,0 +1,38 @@
# Cloudflare
[Cloudflare](https://cloudflare.com/) tools for compiled Hugo-website.
## Install
### Config
[Import module](https://gohugo.io/hugo-modules/use-modules/#use-a-module-for-a-theme) in your site
configuration:
```yaml
imports:
- path: gitlab.com/toby3d/hugo/cloudflare
```
Then, connect and configure the necessary/all modules.
## Web Analytics
[See the official Cloudflare documentation](https://blog.cloudflare.com/privacy-first-web-analytics/)
about how it works and how to get the token.
### Install
#### Config
```yaml
baseUrl: https://example.com/
params:
cloudflare:
webAnalytics: 1d59a54b73a94728a4a9ed1b09767b1f
```
#### Template
Inject `cloudflare/web-analytics` partial in your `<body>` (preferably as close as possible to the closing tag):
```html
...
<body>
...
{{ partial "cloudflare/web-analytics" . }}
</body>
```

8
cloudflare/config.yaml Normal file
View File

@ -0,0 +1,8 @@
---
module:
hugoVersion:
extended: false
min: "0.79.0"
mounts:
- source: layouts/partials
target: layouts/partials/cloudflare

3
cloudflare/go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitlab.com/toby3d/hugo/cloudflare
go 1.15

View File

@ -0,0 +1,5 @@
{{ with $.Site.Params.cloudflare.webAnalytics }}
<!-- Cloudflare Web Analytics -->
<script defer src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon="{'token':'{{ . | safeJS }}'}"></script>
<!-- End Cloudflare Web Analytics -->
{{ end }}