配置
Syntax
SITE.Config
Returns
page.SiteConfig
Site
对象上的 Config
方法提供了访问网站配置的子集,具体包括 services
和 privacy
键。
服务
这些是默认的服务设置,通常由 Hugo 的内置模板和简码使用。
hugo.
services:
disqus:
shortname: ""
googleAnalytics:
id: ""
instagram:
accessToken: ""
disableInlineCSS: false
rss:
limit: -1
twitter:
disableInlineCSS: false
[services]
[services.disqus]
shortname = ''
[services.googleAnalytics]
id = ''
[services.instagram]
accessToken = ''
disableInlineCSS = false
[services.rss]
limit = -1
[services.twitter]
disableInlineCSS = false
{
"services": {
"disqus": {
"shortname": ""
},
"googleAnalytics": {
"id": ""
},
"instagram": {
"accessToken": "",
"disableInlineCSS": false
},
"rss": {
"limit": -1
},
"twitter": {
"disableInlineCSS": false
}
}
}
例如,要使用 Hugo 的内置 Google Analytics 模板,您必须添加一个 Google 标签 ID:
hugo.
services:
googleAnalytics:
id: G-XXXXXXXXX
[services]
[services.googleAnalytics]
id = 'G-XXXXXXXXX'
{
"services": {
"googleAnalytics": {
"id": "G-XXXXXXXXX"
}
}
}
要从模板中访问此值:
{{ .Site.Config.Services.GoogleAnalytics.ID }} → G-XXXXXXXXX
您必须像上面所示每个标识符大写。
隐私
这些是默认的隐私设置,通常由 Hugo 的内置模板和简码使用。
hugo.
privacy:
disqus:
disable: false
googleAnalytics:
anonymizeIP: false
disable: false
respectDoNotTrack: false
useSessionStorage: false
instagram:
disable: false
simple: false
twitter:
disable: false
enableDNT: false
simple: false
vimeo:
disable: false
enableDNT: false
simple: false
youTube:
disable: false
privacyEnhanced: false
[privacy]
[privacy.disqus]
disable = false
[privacy.googleAnalytics]
anonymizeIP = false
disable = false
respectDoNotTrack = false
useSessionStorage = false
[privacy.instagram]
disable = false
simple = false
[privacy.twitter]
disable = false
enableDNT = false
simple = false
[privacy.vimeo]
disable = false
enableDNT = false
simple = false
[privacy.youTube]
disable = false
privacyEnhanced = false
{
"privacy": {
"disqus": {
"disable": false
},
"googleAnalytics": {
"anonymizeIP": false,
"disable": false,
"respectDoNotTrack": false,
"useSessionStorage": false
},
"instagram": {
"disable": false,
"simple": false
},
"twitter": {
"disable": false,
"enableDNT": false,
"simple": false
},
"vimeo": {
"disable": false,
"enableDNT": false,
"simple": false
},
"youTube": {
"disable": false,
"privacyEnhanced": false
}
}
}
例如,要禁用内置的 YouTube 简码的使用:
hugo.
privacy:
youtube:
disable: true
[privacy]
[privacy.youtube]
disable = true
{
"privacy": {
"youtube": {
"disable": true
}
}
}
要从模板中访问此值:
{{ .Site.Config.Privacy.YouTube.Disable }} → true
您必须像上面所示每个标识符大写。