Debian Codegraph @

config/privacy/privacyConfig.go

raw
1 // Copyright 2018 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package privacy
15
16 import (
17 "github.com/gohugoio/hugo/config"
18 "github.com/mitchellh/mapstructure"
19 )
20
21 const privacyConfigKey = "privacy"
22
23 // Service is the common values for a service in a policy definition.
24 type Service struct {
25 Disable bool
26 }
27
28 // Config is a privacy configuration for all the relevant services in Hugo.
29 type Config struct {
30 Disqus Disqus
31 GoogleAnalytics GoogleAnalytics
32 Instagram Instagram
33 Vimeo Vimeo
34 YouTube YouTube
35 X X
36 }
37
38 // Disqus holds the privacy configuration settings related to the Disqus template.
39 type Disqus struct {
40 Service `mapstructure:",squash"`
41 }
42
43 // GoogleAnalytics holds the privacy configuration settings related to the Google Analytics template.
44 type GoogleAnalytics struct {
45 Service `mapstructure:",squash"`
46
47 // Enabling this will make the GA templates respect the
48 // "Do Not Track" HTTP header. See https://www.paulfurley.com/google-analytics-dnt/.
49 RespectDoNotTrack bool
50 }
51
52 // Instagram holds the privacy configuration settings related to the Instagram shortcode.
53 type Instagram struct {
54 Service `mapstructure:",squash"`
55
56 // If simple mode is enabled, a static and no-JS version of the Instagram
57 // image card will be built.
58 Simple bool
59 }
60
61 // Vimeo holds the privacy configuration settings related to the Vimeo shortcode.
62 type Vimeo struct {
63 Service `mapstructure:",squash"`
64
65 // When set to true, the Vimeo player will be blocked from tracking any session data,
66 // including all cookies and stats.
67 EnableDNT bool
68
69 // If simple mode is enabled, only a thumbnail is fetched from i.vimeocdn.com and
70 // shown with a play button overlaid. If a user clicks the button, he/she will
71 // be taken to the video page on vimeo.com in a new browser tab.
72 Simple bool
73 }
74
75 // YouTube holds the privacy configuration settings related to the YouTube shortcode.
76 type YouTube struct {
77 Service `mapstructure:",squash"`
78
79 // When you turn on privacy-enhanced mode,
80 // YouTube won’t store information about visitors on your website
81 // unless the user plays the embedded video.
82 PrivacyEnhanced bool
83 }
84
85 // X holds the privacy configuration settings related to the X shortcode.
86 type X struct {
87 Service `mapstructure:",squash"`
88
89 // When set to true, the X post and its embedded page on your site are not
90 // used for purposes that include personalized suggestions and personalized
91 // ads.
92 EnableDNT bool
93
94 // If simple mode is enabled, a static and no-JS version of the X post will
95 // be built.
96 Simple bool
97 }
98
99 // DecodeConfig creates a privacy Config from a given Hugo configuration.
100 func DecodeConfig(cfg config.Provider) (pc Config, err error) {
101 pc.GoogleAnalytics.RespectDoNotTrack = true
102 m := cfg.GetStringMap(privacyConfigKey)
103 err = mapstructure.WeakDecode(m, &pc)
104
105 return
106 }