servicesConfig.go - hugo - [fork] hugo port for 9front
HTML git clone https://git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
servicesConfig.go (3534B)
---
1 // Copyright 2019 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 rssLimitKey = "rssLimit"
27 )
28
29 // Config is a privacy configuration for all the relevant services in Hugo.
30 type Config struct {
31 Disqus Disqus
32 GoogleAnalytics GoogleAnalytics
33 Instagram Instagram
34 Twitter Twitter // deprecated in favor of X in v0.141.0
35 X X
36 RSS RSS
37 }
38
39 // Disqus holds the functional configuration settings related to the Disqus template.
40 type Disqus struct {
41 // A Shortname is the unique identifier assigned to a Disqus site.
42 Shortname string
43 }
44
45 // GoogleAnalytics holds the functional configuration settings related to the Google Analytics template.
46 type GoogleAnalytics struct {
47 // The GA tracking ID.
48 ID string
49 }
50
51 // Instagram holds the functional configuration settings related to the Instagram shortcodes.
52 type Instagram struct {
53 // The Simple variant of the Instagram is decorated with Bootstrap 4 card classes.
54 // This means that if you use Bootstrap 4 or want to provide your own CSS, you want
55 // to disable the inline CSS provided by Hugo.
56 DisableInlineCSS bool
57
58 // App or Client Access Token.
59 // If you are using a Client Access Token, remember that you must combine it with your App ID
60 // using a pipe symbol (<APPID>|<CLIENTTOKEN>) otherwise the request will fail.
61 AccessToken string
62 }
63
64 // Twitter holds the functional configuration settings related to the Twitter shortcodes.
65 // Deprecated in favor of X in v0.141.0.
66 type Twitter struct {
67 // The Simple variant of Twitter is decorated with a basic set of inline styles.
68 // This means that if you want to provide your own CSS, you want
69 // to disable the inline CSS provided by Hugo.
70 DisableInlineCSS bool
71 }
72
73 // X holds the functional configuration settings related to the X shortcodes.
74 type X struct {
75 // The Simple variant of X is decorated with a basic set of inline styles.
76 // This means that if you want to provide your own CSS, you want
77 // to disable the inline CSS provided by Hugo.
78 DisableInlineCSS bool
79 }
80
81 // RSS holds the functional configuration settings related to the RSS feeds.
82 type RSS struct {
83 // Limit the number of pages.
84 Limit int
85 }
86
87 // DecodeConfig creates a services Config from a given Hugo configuration.
88 func DecodeConfig(cfg config.Provider) (c Config, err error) {
89 m := cfg.GetStringMap(servicesConfigKey)
90
91 err = mapstructure.WeakDecode(m, &c)
92
93 // Keep backwards compatibility.
94 if c.GoogleAnalytics.ID == "" {
95 // Try the global config
96 c.GoogleAnalytics.ID = cfg.GetString(googleAnalyticsKey)
97 }
98 if c.Disqus.Shortname == "" {
99 c.Disqus.Shortname = cfg.GetString(disqusShortnameKey)
100 }
101
102 if c.RSS.Limit == 0 {
103 c.RSS.Limit = cfg.GetInt(rssLimitKey)
104 if c.RSS.Limit == 0 {
105 c.RSS.Limit = -1
106 }
107 }
108
109 return
110 }