github.com/pietrocarrara/hugo@v0.47.1/config/services/servicesConfig.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 services
    15  
    16  import (
    17  	"github.com/gohugoio/hugo/config"
    18  	"github.com/mitchellh/mapstructure"
    19  )
    20  
    21  const (
    22  	servicesConfigKey = "services"
    23  
    24  	disqusShortnameKey = "disqusshortname"
    25  	googleAnalyticsKey = "googleanalytics"
    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  }
    35  
    36  // Disqus holds the functional configuration settings related to the Disqus template.
    37  type Disqus struct {
    38  	// A Shortname is the unique identifier assigned to a Disqus site.
    39  	Shortname string
    40  }
    41  
    42  // GoogleAnalytics holds the functional configuration settings related to the Google Analytics template.
    43  type GoogleAnalytics struct {
    44  	// The GA tracking ID.
    45  	ID string
    46  }
    47  
    48  // Instagram holds the functional configuration settings related to the Instagram shortcodes.
    49  type Instagram struct {
    50  	// The Simple variant of the Instagram is decorated with Bootstrap 4 card classes.
    51  	// This means that if you use Bootstrap 4 or want to provide your own CSS, you want
    52  	// to disable the inline CSS provided by Hugo.
    53  	DisableInlineCSS bool
    54  }
    55  
    56  // Twitter holds the functional configuration settings related to the Twitter shortcodes.
    57  type Twitter struct {
    58  	// The Simple variant of Twitter is decorated with a basic set of inline styles.
    59  	// This means that if you want to provide your own CSS, you want
    60  	// to disable the inline CSS provided by Hugo.
    61  	DisableInlineCSS bool
    62  }
    63  
    64  func DecodeConfig(cfg config.Provider) (c Config, err error) {
    65  	m := cfg.GetStringMap(servicesConfigKey)
    66  
    67  	err = mapstructure.WeakDecode(m, &c)
    68  
    69  	// Keep backwards compatibility.
    70  	if c.GoogleAnalytics.ID == "" {
    71  		// Try the global config
    72  		c.GoogleAnalytics.ID = cfg.GetString(googleAnalyticsKey)
    73  	}
    74  	if c.Disqus.Shortname == "" {
    75  		c.Disqus.Shortname = cfg.GetString(disqusShortnameKey)
    76  	}
    77  
    78  	return
    79  }