github.com/sunshinekia/hugo@v0.47.1/config/privacy/privacyConfig.go (about)

     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  	Twitter         Twitter
    34  	Vimeo           Vimeo
    35  	YouTube         YouTube
    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 disable the use of Cookies and use Session Storage to Store the GA Client ID.
    48  	UseSessionStorage bool
    49  
    50  	// Enabling this will make the GA templates respect the
    51  	// "Do Not Track" HTTP header. See  https://www.paulfurley.com/google-analytics-dnt/.
    52  	RespectDoNotTrack bool
    53  
    54  	// Enabling this will make it so the users' IP addresses are anonymized within Google Analytics.
    55  	AnonymizeIP bool
    56  }
    57  
    58  // Instagram holds the privacy configuration settings related to the Instagram shortcode.
    59  type Instagram struct {
    60  	Service `mapstructure:",squash"`
    61  
    62  	// If simple mode is enabled, a static and no-JS version of the Instagram
    63  	// image card will be built.
    64  	Simple bool
    65  }
    66  
    67  // Twitter holds the privacy configuration settingsrelated to the Twitter shortcode.
    68  type Twitter struct {
    69  	Service `mapstructure:",squash"`
    70  
    71  	// When set to true, the Tweet and its embedded page on your site are not used
    72  	// for purposes that include personalized suggestions and personalized ads.
    73  	EnableDNT bool
    74  
    75  	// If simple mode is enabled, a static and no-JS version of the Tweet will be built.
    76  	Simple bool
    77  }
    78  
    79  // Vimeo holds the privacy configuration settingsrelated to the Vimeo shortcode.
    80  type Vimeo struct {
    81  	Service `mapstructure:",squash"`
    82  
    83  	// If simple mode is enabled, only a thumbnail is fetched from i.vimeocdn.com and
    84  	// shown with a play button overlaid. If a user clicks the button, he/she will
    85  	// be taken to the video page on vimeo.com in a new browser tab.
    86  	Simple bool
    87  }
    88  
    89  // YouTube holds the privacy configuration settingsrelated to the YouTube shortcode.
    90  type YouTube struct {
    91  	Service `mapstructure:",squash"`
    92  
    93  	// When you turn on privacy-enhanced mode,
    94  	// YouTube won’t store information about visitors on your website
    95  	// unless the user plays the embedded video.
    96  	PrivacyEnhanced bool
    97  }
    98  
    99  func DecodeConfig(cfg config.Provider) (pc Config, err error) {
   100  	if !cfg.IsSet(privacyConfigKey) {
   101  		return
   102  	}
   103  
   104  	m := cfg.GetStringMap(privacyConfigKey)
   105  
   106  	err = mapstructure.WeakDecode(m, &pc)
   107  
   108  	return
   109  }