hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

privacyConfig.go (3648B)

    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 	// When set to true, the Vimeo player will be blocked from tracking any session data,
   84 	// including all cookies and stats.
   85 	EnableDNT bool
   86 
   87 	// If simple mode is enabled, only a thumbnail is fetched from i.vimeocdn.com and
   88 	// shown with a play button overlaid. If a user clicks the button, he/she will
   89 	// be taken to the video page on vimeo.com in a new browser tab.
   90 	Simple bool
   91 }
   92 
   93 // YouTube holds the privacy configuration settingsrelated to the YouTube shortcode.
   94 type YouTube struct {
   95 	Service `mapstructure:",squash"`
   96 
   97 	// When you turn on privacy-enhanced mode,
   98 	// YouTube won’t store information about visitors on your website
   99 	// unless the user plays the embedded video.
  100 	PrivacyEnhanced bool
  101 }
  102 
  103 // DecodeConfig creates a privacy Config from a given Hugo configuration.
  104 func DecodeConfig(cfg config.Provider) (pc Config, err error) {
  105 	if !cfg.IsSet(privacyConfigKey) {
  106 		return
  107 	}
  108 
  109 	m := cfg.GetStringMap(privacyConfigKey)
  110 
  111 	err = mapstructure.WeakDecode(m, &pc)
  112 
  113 	return
  114 }