mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-09 19:26:41 +00:00
Compare commits
8 commits
77e4ae7bd4
...
8114b9b751
Author | SHA1 | Date | |
---|---|---|---|
8114b9b751 | |||
74ce5dc841 | |||
54a8f0ce21 | |||
38e05bd3c7 | |||
ebfca61ac4 | |||
e1917740af | |||
b5c5a8bd76 | |||
c9e679075f |
|
@ -44,15 +44,9 @@ type Disqus struct {
|
||||||
type GoogleAnalytics struct {
|
type GoogleAnalytics struct {
|
||||||
Service `mapstructure:",squash"`
|
Service `mapstructure:",squash"`
|
||||||
|
|
||||||
// Enabling this will disable the use of Cookies and use Session Storage to Store the GA Client ID.
|
|
||||||
UseSessionStorage bool
|
|
||||||
|
|
||||||
// Enabling this will make the GA templates respect the
|
// Enabling this will make the GA templates respect the
|
||||||
// "Do Not Track" HTTP header. See https://www.paulfurley.com/google-analytics-dnt/.
|
// "Do Not Track" HTTP header. See https://www.paulfurley.com/google-analytics-dnt/.
|
||||||
RespectDoNotTrack bool
|
RespectDoNotTrack bool
|
||||||
|
|
||||||
// Enabling this will make it so the users' IP addresses are anonymized within Google Analytics.
|
|
||||||
AnonymizeIP bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instagram holds the privacy configuration settings related to the Instagram shortcode.
|
// Instagram holds the privacy configuration settings related to the Instagram shortcode.
|
||||||
|
|
|
@ -33,8 +33,6 @@ disable = true
|
||||||
[privacy.googleAnalytics]
|
[privacy.googleAnalytics]
|
||||||
disable = true
|
disable = true
|
||||||
respectDoNotTrack = true
|
respectDoNotTrack = true
|
||||||
anonymizeIP = true
|
|
||||||
useSessionStorage = true
|
|
||||||
[privacy.instagram]
|
[privacy.instagram]
|
||||||
disable = true
|
disable = true
|
||||||
simple = true
|
simple = true
|
||||||
|
@ -60,8 +58,7 @@ simple = true
|
||||||
|
|
||||||
got := []bool{
|
got := []bool{
|
||||||
pc.Disqus.Disable, pc.GoogleAnalytics.Disable,
|
pc.Disqus.Disable, pc.GoogleAnalytics.Disable,
|
||||||
pc.GoogleAnalytics.RespectDoNotTrack, pc.GoogleAnalytics.AnonymizeIP,
|
pc.GoogleAnalytics.RespectDoNotTrack, pc.Instagram.Disable,
|
||||||
pc.GoogleAnalytics.UseSessionStorage, pc.Instagram.Disable,
|
|
||||||
pc.Instagram.Simple, pc.Twitter.Disable, pc.Twitter.EnableDNT,
|
pc.Instagram.Simple, pc.Twitter.Disable, pc.Twitter.EnableDNT,
|
||||||
pc.Twitter.Simple, pc.Vimeo.Disable, pc.Vimeo.EnableDNT, pc.Vimeo.Simple,
|
pc.Twitter.Simple, pc.Vimeo.Disable, pc.Vimeo.EnableDNT, pc.Vimeo.Simple,
|
||||||
pc.YouTube.PrivacyEnhanced, pc.YouTube.Disable,
|
pc.YouTube.PrivacyEnhanced, pc.YouTube.Disable,
|
||||||
|
|
|
@ -1557,10 +1557,8 @@ config:
|
||||||
disqus:
|
disqus:
|
||||||
disable: false
|
disable: false
|
||||||
googleAnalytics:
|
googleAnalytics:
|
||||||
anonymizeIP: false
|
|
||||||
disable: false
|
disable: false
|
||||||
respectDoNotTrack: false
|
respectDoNotTrack: false
|
||||||
useSessionStorage: false
|
|
||||||
instagram:
|
instagram:
|
||||||
disable: false
|
disable: false
|
||||||
simple: false
|
simple: false
|
||||||
|
|
|
@ -15,8 +15,6 @@ package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
qt "github.com/frankban/quicktest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInternalTemplatesImage(t *testing.T) {
|
func TestInternalTemplatesImage(t *testing.T) {
|
||||||
|
@ -70,9 +68,9 @@ title: My Site
|
||||||
<meta property="article:published_time" content="2021-02-26T18:02:00-01:00" />
|
<meta property="article:published_time" content="2021-02-26T18:02:00-01:00" />
|
||||||
<meta property="article:modified_time" content="2021-05-22T19:25:00-01:00" />
|
<meta property="article:modified_time" content="2021-05-22T19:25:00-01:00" />
|
||||||
<meta itemprop="name" content="My Bundle">
|
<meta itemprop="name" content="My Bundle">
|
||||||
<meta itemprop="image" content="https://example.org/mybundle/featured-sunset.jpg" />
|
<meta itemprop="image" content="https://example.org/mybundle/featured-sunset.jpg">
|
||||||
<meta itemprop="datePublished" content="2021-02-26T18:02:00-01:00" />
|
<meta itemprop="datePublished" content="2021-02-26T18:02:00-01:00">
|
||||||
<meta itemprop="dateModified" content="2021-05-22T19:25:00-01:00" />
|
<meta itemprop="dateModified" content="2021-05-22T19:25:00-01:00">
|
||||||
|
|
||||||
`)
|
`)
|
||||||
b.AssertFileContent("public/mypage/index.html", `
|
b.AssertFileContent("public/mypage/index.html", `
|
||||||
|
@ -83,57 +81,20 @@ title: My Site
|
||||||
<meta property="og:image" content="https://example.org/mypage/sample.jpg" />
|
<meta property="og:image" content="https://example.org/mypage/sample.jpg" />
|
||||||
<meta property="article:published_time" content="2021-02-26T18:02:00+01:00" />
|
<meta property="article:published_time" content="2021-02-26T18:02:00+01:00" />
|
||||||
<meta property="article:modified_time" content="2021-05-22T19:25:00+01:00" />
|
<meta property="article:modified_time" content="2021-05-22T19:25:00+01:00" />
|
||||||
<meta itemprop="image" content="https://example.org/pageimg1.jpg" />
|
<meta itemprop="image" content="https://example.org/pageimg1.jpg">
|
||||||
<meta itemprop="image" content="https://example.org/pageimg2.jpg" />
|
<meta itemprop="image" content="https://example.org/pageimg2.jpg">
|
||||||
<meta itemprop="image" content="https://example.local/logo.png" />
|
<meta itemprop="image" content="https://example.local/logo.png">
|
||||||
<meta itemprop="image" content="https://example.org/mypage/sample.jpg" />
|
<meta itemprop="image" content="https://example.org/mypage/sample.jpg">
|
||||||
<meta itemprop="datePublished" content="2021-02-26T18:02:00+01:00" />
|
<meta itemprop="datePublished" content="2021-02-26T18:02:00+01:00">
|
||||||
<meta itemprop="dateModified" content="2021-05-22T19:25:00+01:00" />
|
<meta itemprop="dateModified" content="2021-05-22T19:25:00+01:00">
|
||||||
`)
|
`)
|
||||||
b.AssertFileContent("public/mysite/index.html", `
|
b.AssertFileContent("public/mysite/index.html", `
|
||||||
<meta name="twitter:image" content="https://example.org/siteimg1.jpg" />
|
<meta name="twitter:image" content="https://example.org/siteimg1.jpg" />
|
||||||
<meta property="og:image" content="https://example.org/siteimg1.jpg" />
|
<meta property="og:image" content="https://example.org/siteimg1.jpg" />
|
||||||
<meta itemprop="image" content="https://example.org/siteimg1.jpg" />
|
<meta itemprop="image" content="https://example.org/siteimg1.jpg">
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just some simple test of the embedded templates to avoid
|
|
||||||
// https://github.com/gohugoio/hugo/issues/4757 and similar.
|
|
||||||
func TestEmbeddedTemplates(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
c := qt.New(t)
|
|
||||||
c.Assert(true, qt.Equals, true)
|
|
||||||
|
|
||||||
home := []string{"index.html", `
|
|
||||||
GA:
|
|
||||||
{{ template "_internal/google_analytics.html" . }}
|
|
||||||
|
|
||||||
GA async:
|
|
||||||
|
|
||||||
{{ template "_internal/google_analytics_async.html" . }}
|
|
||||||
|
|
||||||
Disqus:
|
|
||||||
|
|
||||||
{{ template "_internal/disqus.html" . }}
|
|
||||||
|
|
||||||
`}
|
|
||||||
|
|
||||||
b := newTestSitesBuilder(t)
|
|
||||||
b.WithSimpleConfigFile().WithTemplatesAdded(home...)
|
|
||||||
|
|
||||||
b.Build(BuildCfg{})
|
|
||||||
|
|
||||||
// Gheck GA regular and async
|
|
||||||
b.AssertFileContent("public/index.html",
|
|
||||||
"'anonymizeIp', true",
|
|
||||||
"'script','https://www.google-analytics.com/analytics.js','ga');\n\tga('create', 'UA-ga_id', 'auto')",
|
|
||||||
"<script async src='https://www.google-analytics.com/analytics.js'>")
|
|
||||||
|
|
||||||
// Disqus
|
|
||||||
b.AssertFileContent("public/index.html", "\"disqus_shortname\" + '.disqus.com/embed.js';")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEmbeddedPaginationTemplate(t *testing.T) {
|
func TestEmbeddedPaginationTemplate(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
@ -449,7 +449,9 @@ func (s *Site) Params() maps.Params {
|
||||||
|
|
||||||
// Deprecated: Use taxonomies instead.
|
// Deprecated: Use taxonomies instead.
|
||||||
func (s *Site) Author() map[string]any {
|
func (s *Site) Author() map[string]any {
|
||||||
hugo.Deprecate(".Site.Author", "Use taxonomies instead.", "v0.124.0")
|
if len(s.conf.Author) != 0 {
|
||||||
|
hugo.Deprecate(".Site.Author", "Use taxonomies instead.", "v0.124.0")
|
||||||
|
}
|
||||||
return s.conf.Author
|
return s.conf.Author
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -258,7 +258,6 @@ id = "UA-ga_id"
|
||||||
disable = false
|
disable = false
|
||||||
[privacy.googleAnalytics]
|
[privacy.googleAnalytics]
|
||||||
respectDoNotTrack = true
|
respectDoNotTrack = true
|
||||||
anonymizeIP = true
|
|
||||||
[privacy.instagram]
|
[privacy.instagram]
|
||||||
simple = true
|
simple = true
|
||||||
[privacy.twitter]
|
[privacy.twitter]
|
||||||
|
|
25
markup/bibliography/config.go
Normal file
25
markup/bibliography/config.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package bibliography
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
// File containing bibliography. E.g. 'my-doc.bibtex'. By default assumed
|
||||||
|
// to be in BibTex format.
|
||||||
|
Source string
|
||||||
|
|
||||||
|
// Path to .csl file describing citation file.
|
||||||
|
CitationStyle string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Default Config
|
|
@ -17,8 +17,10 @@ import (
|
||||||
"github.com/gohugoio/hugo/common/maps"
|
"github.com/gohugoio/hugo/common/maps"
|
||||||
"github.com/gohugoio/hugo/config"
|
"github.com/gohugoio/hugo/config"
|
||||||
"github.com/gohugoio/hugo/markup/asciidocext/asciidocext_config"
|
"github.com/gohugoio/hugo/markup/asciidocext/asciidocext_config"
|
||||||
|
"github.com/gohugoio/hugo/markup/bibliography"
|
||||||
"github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
|
"github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
|
||||||
"github.com/gohugoio/hugo/markup/highlight"
|
"github.com/gohugoio/hugo/markup/highlight"
|
||||||
|
"github.com/gohugoio/hugo/markup/pandoc/pandoc_config"
|
||||||
"github.com/gohugoio/hugo/markup/tableofcontents"
|
"github.com/gohugoio/hugo/markup/tableofcontents"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
@ -33,12 +35,16 @@ type Config struct {
|
||||||
|
|
||||||
// Table of contents configuration
|
// Table of contents configuration
|
||||||
TableOfContents tableofcontents.Config
|
TableOfContents tableofcontents.Config
|
||||||
|
Bibliography bibliography.Config
|
||||||
|
|
||||||
// Configuration for the Goldmark markdown engine.
|
// Configuration for the Goldmark markdown engine.
|
||||||
Goldmark goldmark_config.Config
|
Goldmark goldmark_config.Config
|
||||||
|
|
||||||
// Configuration for the Asciidoc external markdown engine.
|
// Configuration for the Asciidoc external markdown engine.
|
||||||
AsciidocExt asciidocext_config.Config
|
AsciidocExt asciidocext_config.Config
|
||||||
|
|
||||||
|
// Configuration for Pandoc external markdown engine.
|
||||||
|
Pandoc pandoc_config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func Decode(cfg config.Provider) (conf Config, err error) {
|
func Decode(cfg config.Provider) (conf Config, err error) {
|
||||||
|
@ -102,7 +108,9 @@ var Default = Config{
|
||||||
|
|
||||||
TableOfContents: tableofcontents.DefaultConfig,
|
TableOfContents: tableofcontents.DefaultConfig,
|
||||||
Highlight: highlight.DefaultConfig,
|
Highlight: highlight.DefaultConfig,
|
||||||
|
Bibliography: bibliography.Default,
|
||||||
|
|
||||||
Goldmark: goldmark_config.Default,
|
Goldmark: goldmark_config.Default,
|
||||||
|
Pandoc: pandoc_config.Default,
|
||||||
AsciidocExt: asciidocext_config.Default,
|
AsciidocExt: asciidocext_config.Default,
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,14 +15,34 @@
|
||||||
package pandoc
|
package pandoc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/hexec"
|
"github.com/gohugoio/hugo/common/hexec"
|
||||||
"github.com/gohugoio/hugo/htesting"
|
"github.com/gohugoio/hugo/htesting"
|
||||||
"github.com/gohugoio/hugo/identity"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
|
||||||
|
"github.com/gohugoio/hugo/identity"
|
||||||
|
"github.com/gohugoio/hugo/markup/bibliography"
|
||||||
"github.com/gohugoio/hugo/markup/converter"
|
"github.com/gohugoio/hugo/markup/converter"
|
||||||
"github.com/gohugoio/hugo/markup/internal"
|
"github.com/gohugoio/hugo/markup/internal"
|
||||||
|
"github.com/gohugoio/hugo/markup/pandoc/pandoc_config"
|
||||||
|
|
||||||
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type paramer interface {
|
||||||
|
Param(interface{}) (interface{}, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type searchPaths struct {
|
||||||
|
Paths []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *searchPaths) AsResourcePath() string {
|
||||||
|
return strings.Join(s.Paths, ":")
|
||||||
|
}
|
||||||
|
|
||||||
// Provider is the package entry point.
|
// Provider is the package entry point.
|
||||||
var Provider converter.ProviderProvider = provider{}
|
var Provider converter.ProviderProvider = provider{}
|
||||||
|
|
||||||
|
@ -31,19 +51,19 @@ type provider struct{}
|
||||||
func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error) {
|
func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error) {
|
||||||
return converter.NewProvider("pandoc", func(ctx converter.DocumentContext) (converter.Converter, error) {
|
return converter.NewProvider("pandoc", func(ctx converter.DocumentContext) (converter.Converter, error) {
|
||||||
return &pandocConverter{
|
return &pandocConverter{
|
||||||
ctx: ctx,
|
docCtx: ctx,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
}, nil
|
}, nil
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type pandocConverter struct {
|
type pandocConverter struct {
|
||||||
ctx converter.DocumentContext
|
docCtx converter.DocumentContext
|
||||||
cfg converter.ProviderConfig
|
cfg converter.ProviderConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pandocConverter) Convert(ctx converter.RenderContext) (converter.ResultRender, error) {
|
func (c *pandocConverter) Convert(ctx converter.RenderContext) (converter.ResultRender, error) {
|
||||||
b, err := c.getPandocContent(ctx.Src, c.ctx)
|
b, err := c.getPandocContent(ctx.Src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -55,30 +75,50 @@ func (c *pandocConverter) Supports(feature identity.Identity) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPandocContent calls pandoc as an external helper to convert pandoc markdown to HTML.
|
// getPandocContent calls pandoc as an external helper to convert pandoc markdown to HTML.
|
||||||
func (c *pandocConverter) getPandocContent(src []byte, ctx converter.DocumentContext) ([]byte, error) {
|
func (c *pandocConverter) getPandocContent(src []byte) ([]byte, error) {
|
||||||
logger := c.cfg.Logger
|
pandocPath, pandocFound := getPandocBinaryName()
|
||||||
binaryName := getPandocBinaryName()
|
if !pandocFound {
|
||||||
if binaryName == "" {
|
return nil, errors.New("pandoc not found in $PATH: Please install.")
|
||||||
logger.Println("pandoc not found in $PATH: Please install.\n",
|
|
||||||
" Leaving pandoc content unrendered.")
|
|
||||||
return src, nil
|
|
||||||
}
|
}
|
||||||
args := []string{"--mathjax"}
|
|
||||||
return internal.ExternallyRenderContent(c.cfg, ctx, src, binaryName, args)
|
var pandocConfig pandoc_config.Config = c.cfg.MarkupConfig().Pandoc
|
||||||
|
var bibConfig bibliography.Config = c.cfg.MarkupConfig().Bibliography
|
||||||
|
|
||||||
|
if pageParameters, ok := c.docCtx.Document.(paramer); ok {
|
||||||
|
if bibParam, err := pageParameters.Param("bibliography"); err == nil {
|
||||||
|
mapstructure.WeakDecode(bibParam, &bibConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
if pandocParam, err := pageParameters.Param("pandoc"); err == nil {
|
||||||
|
mapstructure.WeakDecode(pandocParam, &pandocConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arguments := pandocConfig.AsPandocArguments()
|
||||||
|
|
||||||
|
if bibConfig.Source != "" {
|
||||||
|
arguments = append(arguments, "--citeproc", "--bibliography", bibConfig.Source)
|
||||||
|
if bibConfig.CitationStyle != "" {
|
||||||
|
arguments = append(arguments, "--csl", bibConfig.CitationStyle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resourcePath := strings.Join([]string{path.Dir(c.docCtx.Filename), "static", "."}, ":")
|
||||||
|
arguments = append(arguments, "--resource-path", resourcePath)
|
||||||
|
|
||||||
|
renderedContent, _ := internal.ExternallyRenderContent(c.cfg, c.docCtx, src, pandocPath, arguments)
|
||||||
|
return renderedContent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const pandocBinary = "pandoc"
|
const pandocBinary = "pandoc"
|
||||||
|
|
||||||
func getPandocBinaryName() string {
|
func getPandocBinaryName() (string, bool) {
|
||||||
if hexec.InPath(pandocBinary) {
|
return pandocBinary, hexec.InPath(pandocBinary)
|
||||||
return pandocBinary
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supports returns whether Pandoc is installed on this computer.
|
// Supports returns whether Pandoc is installed on this computer.
|
||||||
func Supports() bool {
|
func Supports() bool {
|
||||||
hasBin := getPandocBinaryName() != ""
|
_, hasBin := getPandocBinaryName()
|
||||||
if htesting.SupportsAll() {
|
if htesting.SupportsAll() {
|
||||||
if !hasBin {
|
if !hasBin {
|
||||||
panic("pandoc not installed")
|
panic("pandoc not installed")
|
||||||
|
|
165
markup/pandoc/pandoc_config/pandoc.go
Normal file
165
markup/pandoc/pandoc_config/pandoc.go
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
package pandoc_config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config contains configuration settings for Pandoc.
|
||||||
|
type Config struct {
|
||||||
|
// Input format. Use the 'Extensions' field to specify extensions thereof.
|
||||||
|
// Only specify the bare format here. Defaults to 'markdown' if empty. Invoke
|
||||||
|
// "pandoc --list-input-formats" to see the list of supported input formats
|
||||||
|
// including various Markdown dialects.
|
||||||
|
InputFormat string
|
||||||
|
|
||||||
|
// If true, the output format is HTML (i.e. "--to=html"). Otherwise the output
|
||||||
|
// format is HTML5 (i.e. "--to=html5").
|
||||||
|
UseLegacyHtml bool
|
||||||
|
|
||||||
|
// Equivalent to specifying "--mathjax". For compatibility, this option is
|
||||||
|
// always true if none of the other math options are used.
|
||||||
|
// See https://pandoc.org/MANUAL.html#math-rendering-in-html
|
||||||
|
UseMathjax bool
|
||||||
|
|
||||||
|
// Equivalent to specifying "--mathml".
|
||||||
|
// See https://pandoc.org/MANUAL.html#math-rendering-in-html
|
||||||
|
UseMathml bool
|
||||||
|
|
||||||
|
// Equivalent to specifying "--webtex".
|
||||||
|
// See https://pandoc.org/MANUAL.html#math-rendering-in-html. Uses the default
|
||||||
|
// Webtex rendering URL.
|
||||||
|
UseWebtex bool
|
||||||
|
|
||||||
|
// Equivalent to specifying "--katex".
|
||||||
|
// See https://pandoc.org/MANUAL.html#math-rendering-in-html
|
||||||
|
UseKatex bool
|
||||||
|
|
||||||
|
// List of filters to use. These translate to '--filter=' or '--lua-filter'
|
||||||
|
// arguments to the pandoc invocation. The order of elements in `Filters`
|
||||||
|
// is preserved when constructing the `pandoc` commandline.
|
||||||
|
//
|
||||||
|
// Use the prefix 'lua:' or the suffix '.lua' to indicate Lua filters.
|
||||||
|
Filters []string
|
||||||
|
|
||||||
|
// List of Pandoc Markdown extensions to use. No need to include default
|
||||||
|
// extensions. Specifying ["foo", "bar"] is equivalent to specifying
|
||||||
|
// --from=markdown+foo+bar on the pandoc commandline.
|
||||||
|
Extensions []string
|
||||||
|
|
||||||
|
// List of input format extensions to use. Specifying ["foo", "bar"] is
|
||||||
|
// equivalent to specifying --from=markdown+foo+bar on the pandoc commandline
|
||||||
|
// assuming InputFormat is "markdown".
|
||||||
|
InputExtensions []string
|
||||||
|
|
||||||
|
// List of output format extensions to use. Specifying ["foo", "bar"] is
|
||||||
|
// equivalent to specifying --to=html5+foo+bar on the pandoc commandline,
|
||||||
|
// assuming UseLegacyHTML is false. Invoke "pandoc --list-extensions=html5" to
|
||||||
|
// or "pandoc --list-extensions=html5" to see the list of extensions that can
|
||||||
|
// be specified here.
|
||||||
|
OutputExtensions []string
|
||||||
|
|
||||||
|
// Metadata. The dictionary keys and values are handled in the obvious way.
|
||||||
|
Metadata map[string]interface{}
|
||||||
|
|
||||||
|
// Extra commandline options passed to the pandoc invocation. These options
|
||||||
|
// are appended to the commandline after the format and filter options.
|
||||||
|
// Arguments are passed in literally. Hence must have the "--" or "-" prefix
|
||||||
|
// where applicable.
|
||||||
|
ExtraArgs []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Default = Config{
|
||||||
|
InputFormat: "markdown",
|
||||||
|
UseLegacyHtml: false,
|
||||||
|
UseMathjax: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) getInputArg() string {
|
||||||
|
var b strings.Builder
|
||||||
|
b.WriteString("--from=")
|
||||||
|
if len(c.InputFormat) > 0 {
|
||||||
|
b.WriteString(c.InputFormat)
|
||||||
|
} else {
|
||||||
|
b.WriteString("markdown")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, extension := range c.InputExtensions {
|
||||||
|
b.WriteString("+")
|
||||||
|
b.WriteString(extension)
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) getOutputArg() string {
|
||||||
|
var b strings.Builder
|
||||||
|
b.WriteString("--to=")
|
||||||
|
if c.UseLegacyHtml {
|
||||||
|
b.WriteString("html")
|
||||||
|
} else {
|
||||||
|
b.WriteString("html5")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, extension := range c.OutputExtensions {
|
||||||
|
b.WriteString("+")
|
||||||
|
b.WriteString(extension)
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) getMathRenderingArg() string {
|
||||||
|
switch {
|
||||||
|
case c.UseMathml:
|
||||||
|
return "--mathml"
|
||||||
|
case c.UseWebtex:
|
||||||
|
return "--webtex"
|
||||||
|
case c.UseKatex:
|
||||||
|
return "--katex"
|
||||||
|
default:
|
||||||
|
return "--mathjax"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) getMetadataArgs() []string {
|
||||||
|
var args []string
|
||||||
|
for k, iv := range c.Metadata {
|
||||||
|
var v string
|
||||||
|
if sv, ok := iv.(string); ok {
|
||||||
|
v = sv
|
||||||
|
} else if sv, ok := iv.(fmt.Stringer); ok {
|
||||||
|
v = sv.String()
|
||||||
|
} else {
|
||||||
|
v = fmt.Sprintf("%v", iv)
|
||||||
|
}
|
||||||
|
args = append(args, fmt.Sprintf("-M%s=%s", k, v))
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) getFilterArgs() []string {
|
||||||
|
var args []string
|
||||||
|
for _, filterPath := range c.Filters {
|
||||||
|
if strings.HasPrefix(filterPath, "lua:") || strings.HasSuffix(filterPath, ".lua") {
|
||||||
|
args = append(args, fmt.Sprintf("--lua-filter=%s", strings.TrimPrefix(filterPath, "lua:")))
|
||||||
|
} else {
|
||||||
|
args = append(args, fmt.Sprintf("--filter=%s", filterPath))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
// AsPandocArguments returns a list of strings that can be used as arguments to
|
||||||
|
// a "pandoc" invocation. All the settings contained in Config are represented
|
||||||
|
// in the returned list of arguments.
|
||||||
|
func (c *Config) AsPandocArguments() []string {
|
||||||
|
args := []string{
|
||||||
|
c.getInputArg(),
|
||||||
|
c.getOutputArg(),
|
||||||
|
c.getMathRenderingArg()}
|
||||||
|
|
||||||
|
args = append(args, c.getMetadataArgs()...)
|
||||||
|
args = append(args, c.getFilterArgs()...)
|
||||||
|
args = append(args, c.ExtraArgs...)
|
||||||
|
|
||||||
|
return args
|
||||||
|
}
|
|
@ -57,7 +57,7 @@ func New(rs *resources.Spec) *Client {
|
||||||
|
|
||||||
// Copy copies r to the new targetPath.
|
// Copy copies r to the new targetPath.
|
||||||
func (c *Client) Copy(r resource.Resource, targetPath string) (resource.Resource, error) {
|
func (c *Client) Copy(r resource.Resource, targetPath string) (resource.Resource, error) {
|
||||||
key := dynacache.CleanKey(targetPath)
|
key := dynacache.CleanKey(targetPath) + "__copy"
|
||||||
return c.rs.ResourceCache.GetOrCreate(key, func() (resource.Resource, error) {
|
return c.rs.ResourceCache.GetOrCreate(key, func() (resource.Resource, error) {
|
||||||
return resources.Copy(r, targetPath), nil
|
return resources.Copy(r, targetPath), nil
|
||||||
})
|
})
|
||||||
|
@ -66,7 +66,7 @@ func (c *Client) Copy(r resource.Resource, targetPath string) (resource.Resource
|
||||||
// Get creates a new Resource by opening the given pathname in the assets filesystem.
|
// Get creates a new Resource by opening the given pathname in the assets filesystem.
|
||||||
func (c *Client) Get(pathname string) (resource.Resource, error) {
|
func (c *Client) Get(pathname string) (resource.Resource, error) {
|
||||||
pathname = path.Clean(pathname)
|
pathname = path.Clean(pathname)
|
||||||
key := dynacache.CleanKey(pathname)
|
key := dynacache.CleanKey(pathname) + "__get"
|
||||||
|
|
||||||
return c.rs.ResourceCache.GetOrCreate(key, func() (resource.Resource, error) {
|
return c.rs.ResourceCache.GetOrCreate(key, func() (resource.Resource, error) {
|
||||||
// The resource file will not be read before it gets used (e.g. in .Content),
|
// The resource file will not be read before it gets used (e.g. in .Content),
|
||||||
|
|
|
@ -227,3 +227,50 @@ eventDate: 2023-11-01T07:00:00-08:00
|
||||||
|
|
||||||
b.AssertFileContent("public/index.html", "2023-11|p9|p8|p7|2023-10|p6|p5|p4|2023-09|p3|p2|p1|")
|
b.AssertFileContent("public/index.html", "2023-11|p9|p8|p7|2023-10|p6|p5|p4|2023-09|p3|p2|p1|")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue 10412
|
||||||
|
func TestImageTransformThenCopy(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||||
|
-- assets/pixel.png --
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
|
||||||
|
-- layouts/index.html --
|
||||||
|
{{- with resources.Get "pixel.png" }}
|
||||||
|
{{- with .Resize "200x" | resources.Copy "pixel.png" }}
|
||||||
|
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">|{{ .Key }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
`
|
||||||
|
|
||||||
|
b := hugolib.Test(t, files)
|
||||||
|
|
||||||
|
b.AssertFileExists("public/pixel.png", true)
|
||||||
|
b.AssertFileContent("public/index.html",
|
||||||
|
`<img src="/pixel.png" width="200" height="200">|/pixel.png`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue 12310
|
||||||
|
func TestUseDifferentCacheKeyForResourceCopy(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ['page','section','rss','sitemap','taxonomy','term']
|
||||||
|
-- assets/a.txt --
|
||||||
|
This was assets/a.txt
|
||||||
|
-- layouts/index.html --
|
||||||
|
{{ $nilResource := resources.Get "/p1/b.txt" }}
|
||||||
|
{{ $r := resources.Get "a.txt" }}
|
||||||
|
{{ $r = resources.Copy "/p1/b.txt" $r }}
|
||||||
|
{{ $r.RelPermalink }}
|
||||||
|
`
|
||||||
|
|
||||||
|
b, err := hugolib.TestE(t, files)
|
||||||
|
|
||||||
|
b.Assert(err, qt.IsNil)
|
||||||
|
b.AssertFileContent("public/p1/b.txt", "This was assets/a.txt")
|
||||||
|
}
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bep/logg"
|
"github.com/bep/logg"
|
||||||
"github.com/sanity-io/litter"
|
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
"github.com/yuin/goldmark/util"
|
"github.com/yuin/goldmark/util"
|
||||||
|
|
||||||
|
@ -108,7 +108,11 @@ type Namespace struct {
|
||||||
// Also note that the output from Dump may change from Hugo version to the next,
|
// Also note that the output from Dump may change from Hugo version to the next,
|
||||||
// so don't depend on a specific output.
|
// so don't depend on a specific output.
|
||||||
func (ns *Namespace) Dump(val any) string {
|
func (ns *Namespace) Dump(val any) string {
|
||||||
return litter.Sdump(val)
|
b, err := json.MarshalIndent(val, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisualizeSpaces returns a string with spaces replaced by a visible string.
|
// VisualizeSpaces returns a string with spaces replaced by a visible string.
|
||||||
|
|
|
@ -43,3 +43,33 @@ disableKinds = ["taxonomy", "term"]
|
||||||
|
|
||||||
b.AssertLogContains("timer: name foo count 5 duration")
|
b.AssertLogContains("timer: name foo count 5 duration")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDebugDumpPage(t *testing.T) {
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
baseURL = "https://example.org/"
|
||||||
|
disableLiveReload = true
|
||||||
|
[taxonomies]
|
||||||
|
tag = "tags"
|
||||||
|
-- content/_index.md --
|
||||||
|
---
|
||||||
|
title: "The Index"
|
||||||
|
date: 2012-03-15
|
||||||
|
---
|
||||||
|
-- content/p1.md --
|
||||||
|
---
|
||||||
|
title: "The First"
|
||||||
|
tags: ["a", "b"]
|
||||||
|
---
|
||||||
|
-- layouts/_default/list.html --
|
||||||
|
Dump: {{ debug.Dump . | safeHTML }}
|
||||||
|
Dump Site: {{ debug.Dump site }}
|
||||||
|
Dum site.Taxonomies: {{ debug.Dump site.Taxonomies | safeHTML }}
|
||||||
|
-- layouts/_default/single.html --
|
||||||
|
Dump: {{ debug.Dump . | safeHTML }}
|
||||||
|
|
||||||
|
|
||||||
|
`
|
||||||
|
b := hugolib.TestRunning(t, files)
|
||||||
|
b.AssertFileContent("public/index.html", "Dump: {\n \"Date\": \"2012-03-15T00:00:00Z\"")
|
||||||
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
||||||
[][2]string{
|
[][2]string{
|
||||||
{`{{ $m := newScratch }}
|
{`{{ $m := newScratch }}
|
||||||
{{ $m.Set "Hugo" "Rocks!" }}
|
{{ $m.Set "Hugo" "Rocks!" }}
|
||||||
{{ $m.Values | debug.Dump | safeHTML }}`, "map[string]interface {}{\n \"Hugo\": \"Rocks!\",\n}"},
|
{{ $m.Values | debug.Dump | safeHTML }}`, "{\n \"Hugo\": \"Rocks!\"\n}"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,51 +1,22 @@
|
||||||
{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
|
{{ if not site.Config.Privacy.GoogleAnalytics.Disable }}
|
||||||
{{- if not $pc.Disable }}{{ with .Site.Config.Services.GoogleAnalytics.ID -}}
|
{{ with site.Config.Services.GoogleAnalytics.ID }}
|
||||||
{{ if hasPrefix . "G-"}}
|
{{ if strings.HasPrefix (lower .) "ua-" }}
|
||||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
|
{{ warnf "Google Analytics 4 (GA4) replaced Google Universal Analytics (UA) effective 1 July 2023. See https://support.google.com/analytics/answer/11583528. Create a GA4 property and data stream, then replace the Google Analytics ID in your site configuration with the new value." }}
|
||||||
<script>
|
{{ else }}
|
||||||
{{ template "__ga_js_set_doNotTrack" $ }}
|
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
|
||||||
if (!doNotTrack) {
|
<script>
|
||||||
window.dataLayer = window.dataLayer || [];
|
var doNotTrack = false;
|
||||||
function gtag(){dataLayer.push(arguments);}
|
if ({{ site.Config.Privacy.GoogleAnalytics.RespectDoNotTrack }}) {
|
||||||
gtag('js', new Date());
|
var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);
|
||||||
gtag('config', '{{ . }}', { 'anonymize_ip': {{- $pc.AnonymizeIP -}} });
|
var doNotTrack = (dnt == "1" || dnt == "yes");
|
||||||
}
|
}
|
||||||
</script>
|
if (!doNotTrack) {
|
||||||
{{ else if hasPrefix . "UA-" }}
|
window.dataLayer = window.dataLayer || [];
|
||||||
<script>
|
function gtag(){dataLayer.push(arguments);}
|
||||||
{{ template "__ga_js_set_doNotTrack" $ }}
|
gtag('js', new Date());
|
||||||
if (!doNotTrack) {
|
gtag('config', '{{ . }}');
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
}
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
</script>
|
||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
{{ end }}
|
||||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
{{ end }}
|
||||||
{{- if $pc.UseSessionStorage }}
|
{{ end }}
|
||||||
if (window.sessionStorage) {
|
|
||||||
var GA_SESSION_STORAGE_KEY = 'ga:clientId';
|
|
||||||
ga('create', '{{ . }}', {
|
|
||||||
'storage': 'none',
|
|
||||||
'clientId': sessionStorage.getItem(GA_SESSION_STORAGE_KEY)
|
|
||||||
});
|
|
||||||
ga(function(tracker) {
|
|
||||||
sessionStorage.setItem(GA_SESSION_STORAGE_KEY, tracker.get('clientId'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
{{ else }}
|
|
||||||
ga('create', '{{ . }}', 'auto');
|
|
||||||
{{ end -}}
|
|
||||||
{{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end }}
|
|
||||||
ga('send', 'pageview');
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
{{- end -}}
|
|
||||||
{{- end }}{{ end -}}
|
|
||||||
|
|
||||||
{{- define "__ga_js_set_doNotTrack" -}}{{/* This is also used in the async version. */}}
|
|
||||||
{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
|
|
||||||
{{- if not $pc.RespectDoNotTrack -}}
|
|
||||||
var doNotTrack = false;
|
|
||||||
{{- else -}}
|
|
||||||
var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);
|
|
||||||
var doNotTrack = (dnt == "1" || dnt == "yes");
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
{{ warnf "_internal/google_analytics_async.html is no longer supported by Google and will be removed in a future version of Hugo" }}
|
|
||||||
{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
|
|
||||||
{{- if not $pc.Disable -}}
|
|
||||||
{{ with .Site.Config.Services.GoogleAnalytics.ID }}
|
|
||||||
<script>
|
|
||||||
{{ template "__ga_js_set_doNotTrack" $ }}
|
|
||||||
if (!doNotTrack) {
|
|
||||||
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
|
|
||||||
{{- if $pc.UseSessionStorage }}
|
|
||||||
if (window.sessionStorage) {
|
|
||||||
var GA_SESSION_STORAGE_KEY = 'ga:clientId';
|
|
||||||
ga('create', '{{ . }}', {
|
|
||||||
'storage': 'none',
|
|
||||||
'clientId': sessionStorage.getItem(GA_SESSION_STORAGE_KEY)
|
|
||||||
});
|
|
||||||
ga(function(tracker) {
|
|
||||||
sessionStorage.setItem(GA_SESSION_STORAGE_KEY, tracker.get('clientId'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
{{ else }}
|
|
||||||
ga('create', '{{ . }}', 'auto');
|
|
||||||
{{ end -}}
|
|
||||||
{{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end }}
|
|
||||||
ga('send', 'pageview');
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<script async src='https://www.google-analytics.com/analytics.js'></script>
|
|
||||||
{{ end }}
|
|
||||||
{{- end -}}
|
|
|
@ -1,17 +1,56 @@
|
||||||
<meta itemprop="name" content="{{ .Title }}">
|
{{- with or .Title site.Title }}
|
||||||
<meta itemprop="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
|
<meta itemprop="name" content="{{ . }}">
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
{{- if .IsPage -}}
|
{{- with or .Description .Summary site.Params.Description }}
|
||||||
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
|
<meta itemprop="description" content="{{ . }}">
|
||||||
{{ with .PublishDate }}<meta itemprop="datePublished" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}}
|
{{- end }}
|
||||||
{{ with .Lastmod }}<meta itemprop="dateModified" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}}
|
|
||||||
<meta itemprop="wordCount" content="{{ .WordCount }}">
|
|
||||||
|
|
||||||
{{- $images := partial "_funcs/get-page-images" . -}}
|
{{- $ISO8601 := "2006-01-02T15:04:05-07:00" }}
|
||||||
{{- range first 6 $images -}}
|
{{- with .PublishDate }}
|
||||||
<meta itemprop="image" content="{{ .Permalink }}" />
|
<meta itemprop="datePublished" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}>
|
||||||
{{- end -}}
|
{{- end }}
|
||||||
|
|
||||||
<!-- Output all taxonomies as schema.org keywords -->
|
{{- with .Lastmod }}
|
||||||
<meta itemprop="keywords" content="{{ if .IsPage}}{{ range $index, $tag := .Params.tags }}{{ $tag }},{{ end }}{{ else }}{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}{{ printf "%s," $term }}{{ end }}{{ end }}{{ end }}" />
|
<meta itemprop="dateModified" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}>
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- with .WordCount }}
|
||||||
|
<meta itemprop="wordCount" content="{{ . }}">
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- $images := partial "_funcs/get-page-images" . }}
|
||||||
|
{{- range first 6 $images }}
|
||||||
|
<meta itemprop="image" content="{{ .Permalink }}">
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- /*
|
||||||
|
Keywords precedence:
|
||||||
|
|
||||||
|
1. Use "keywords" term page titles.
|
||||||
|
2. Use "keywords" from front matter if "keywords" is not a taxonomy.
|
||||||
|
3. Use "tags" term page titles.
|
||||||
|
4. Use term page titles from all taxonomies.
|
||||||
|
|
||||||
|
*/}}
|
||||||
|
{{- $keywords := slice }}
|
||||||
|
{{- range .GetTerms "keywords" }}
|
||||||
|
{{- $keywords = $keywords | append .Title }}
|
||||||
|
{{- else }}
|
||||||
|
{{- with .Keywords }}
|
||||||
|
{{- $keywords = . }}
|
||||||
|
{{- else }}
|
||||||
|
{{- range .GetTerms "tags" }}
|
||||||
|
{{- $keywords = $keywords | append .Title }}
|
||||||
|
{{- else }}
|
||||||
|
{{- range $taxonomy, $_ := site.Taxonomies }}
|
||||||
|
{{- range $.GetTerms $taxonomy }}
|
||||||
|
{{- $keywords = $keywords | append .Title }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with $keywords }}
|
||||||
|
<meta itemprop="keywords" content="{{ delimit . `,` }}">
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
|
@ -210,3 +210,47 @@ var a = §§{{.Title }}§§;
|
||||||
// This used to fail, but not in >= Hugo 0.121.0.
|
// This used to fail, but not in >= Hugo 0.121.0.
|
||||||
b.Assert(err, qt.IsNil)
|
b.Assert(err, qt.IsNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoogleAnalyticsTemplate(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ['page','section','rss','sitemap','taxonomy','term']
|
||||||
|
[privacy.googleAnalytics]
|
||||||
|
disable = false
|
||||||
|
respectDoNotTrack = true
|
||||||
|
[services.googleAnalytics]
|
||||||
|
id = 'G-0123456789'
|
||||||
|
-- layouts/index.html --
|
||||||
|
{{ template "_internal/google_analytics.html" . }}
|
||||||
|
`
|
||||||
|
|
||||||
|
b := hugolib.Test(t, files)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.html",
|
||||||
|
`<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`,
|
||||||
|
`var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDisqusTemplate(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ['page','section','rss','sitemap','taxonomy','term']
|
||||||
|
[services.disqus]
|
||||||
|
shortname = 'foo'
|
||||||
|
[privacy.disqus]
|
||||||
|
disable = false
|
||||||
|
-- layouts/index.html --
|
||||||
|
{{ template "_internal/disqus.html" . }}
|
||||||
|
`
|
||||||
|
|
||||||
|
b := hugolib.Test(t, files)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.html",
|
||||||
|
`s.src = '//' + "foo" + '.disqus.com/embed.js';`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue