mirror of
https://github.com/gohugoio/hugo.git
synced 2026-09-01 11:12:37 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 252d0cf52a | |||
| ec22bb31a8 | |||
| a795acbcd8 | |||
| 982d9513e7 | |||
| 6dedb4efc7 | |||
| 292626e679 | |||
| 60d954c785 | |||
| 63e0a92894 | |||
| ce7daa6156 | |||
| 2a0329423c | |||
| 50dc327d1a |
Vendored
+1
-3
@@ -15,6 +15,7 @@
|
||||
package filecache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -24,8 +25,6 @@ import (
|
||||
"github.com/gohugoio/hugo/common/maps"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
@@ -225,7 +224,6 @@ func DecodeConfig(fs afero.Fs, bcfg config.BaseConfig, m map[string]any) (Config
|
||||
|
||||
// Resolves :resourceDir => /myproject/resources etc., :cacheDir => ...
|
||||
func resolveDirPlaceholder(fs afero.Fs, bcfg config.BaseConfig, placeholder string) (cacheDir string, isResource bool, err error) {
|
||||
|
||||
switch strings.ToLower(placeholder) {
|
||||
case ":resourcedir":
|
||||
return "", true, nil
|
||||
|
||||
Vendored
-2
@@ -60,7 +60,6 @@ func (c *Cache) Prune(force bool) (int, error) {
|
||||
counter := 0
|
||||
|
||||
err := afero.Walk(c.Fs, "", func(name string, info os.FileInfo, err error) error {
|
||||
|
||||
if info == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -69,7 +68,6 @@ func (c *Cache) Prune(force bool) (int, error) {
|
||||
|
||||
if info.IsDir() {
|
||||
f, err := c.Fs.Open(name)
|
||||
|
||||
if err != nil {
|
||||
// This cache dir may not exist.
|
||||
return nil
|
||||
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env bash
|
||||
diff <(gofmt -d .) <(printf '')
|
||||
@@ -461,7 +461,6 @@ func collectMethodsRecursive(pkg string, f []*ast.Field) []string {
|
||||
pkg,
|
||||
tt.Methods.List)...)
|
||||
}
|
||||
|
||||
} else {
|
||||
// Embedded, but in a different file/package. Return the
|
||||
// package.Name and deal with that later.
|
||||
|
||||
@@ -55,7 +55,7 @@ func TestAppend(t *testing.T) {
|
||||
[]any{&tstSlicerIn1{"c"}},
|
||||
testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}, &tstSlicerIn1{"c"}},
|
||||
},
|
||||
//https://github.com/gohugoio/hugo/issues/5361
|
||||
// https://github.com/gohugoio/hugo/issues/5361
|
||||
{
|
||||
[]string{"a", "b"},
|
||||
[]any{tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}},
|
||||
@@ -102,14 +102,16 @@ func TestAppendToMultiDimensionalSlice(t *testing.T) {
|
||||
from []any
|
||||
expected any
|
||||
}{
|
||||
{[][]string{{"a", "b"}},
|
||||
{
|
||||
[][]string{{"a", "b"}},
|
||||
[]any{[]string{"c", "d"}},
|
||||
[][]string{
|
||||
{"a", "b"},
|
||||
{"c", "d"},
|
||||
},
|
||||
},
|
||||
{[][]string{{"a", "b"}},
|
||||
{
|
||||
[][]string{{"a", "b"}},
|
||||
[]any{[]string{"c", "d"}, []string{"e", "f"}},
|
||||
[][]string{
|
||||
{"a", "b"},
|
||||
@@ -117,7 +119,8 @@ func TestAppendToMultiDimensionalSlice(t *testing.T) {
|
||||
{"e", "f"},
|
||||
},
|
||||
},
|
||||
{[][]string{{"a", "b"}},
|
||||
{
|
||||
[][]string{{"a", "b"}},
|
||||
[]any{[]int{1, 2}},
|
||||
false,
|
||||
},
|
||||
@@ -130,7 +133,6 @@ func TestAppendToMultiDimensionalSlice(t *testing.T) {
|
||||
c.Assert(result, qt.DeepEquals, test.expected)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAppendShouldMakeACopyOfTheInputSlice(t *testing.T) {
|
||||
|
||||
@@ -73,7 +73,6 @@ func StringSliceToInterfaceSlice(ss []string) []any {
|
||||
result[i] = s
|
||||
}
|
||||
return result
|
||||
|
||||
}
|
||||
|
||||
type SortedStringSlice []string
|
||||
|
||||
@@ -135,5 +135,4 @@ func TestSortedStringSlice(t *testing.T) {
|
||||
c.Assert(s.Count("b"), qt.Equals, 3)
|
||||
c.Assert(s.Count("z"), qt.Equals, 0)
|
||||
c.Assert(s.Count("a"), qt.Equals, 1)
|
||||
|
||||
}
|
||||
|
||||
@@ -19,11 +19,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/cli/safeexec"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
@@ -142,7 +141,6 @@ func (e *Exec) New(name string, arg ...any) (Runner, error) {
|
||||
}
|
||||
|
||||
return cm.command(arg...)
|
||||
|
||||
}
|
||||
|
||||
// Npx is a convenience method to create a Runner running npx --no-install <name> <args.
|
||||
|
||||
@@ -47,12 +47,7 @@ defaultContentLanguage = 'it'
|
||||
{{ end }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
month: _gennaio_ weekday: _lunedì_
|
||||
@@ -53,7 +53,6 @@ func TestTimeFormatter(t *testing.T) {
|
||||
c.Assert(f.Format(june06, ":time_long"), qt.Equals, "02:09:37 UTC")
|
||||
c.Assert(f.Format(june06, ":time_medium"), qt.Equals, "02:09:37")
|
||||
c.Assert(f.Format(june06, ":time_short"), qt.Equals, "02:09")
|
||||
|
||||
})
|
||||
|
||||
c.Run("Custom layouts English", func(c *qt.C) {
|
||||
@@ -68,7 +67,6 @@ func TestTimeFormatter(t *testing.T) {
|
||||
c.Assert(f.Format(june06, ":time_long"), qt.Equals, "2:09:37 am UTC")
|
||||
c.Assert(f.Format(june06, ":time_medium"), qt.Equals, "2:09:37 am")
|
||||
c.Assert(f.Format(june06, ":time_short"), qt.Equals, "2:09 am")
|
||||
|
||||
})
|
||||
|
||||
c.Run("English", func(c *qt.C) {
|
||||
@@ -107,9 +105,7 @@ func TestTimeFormatter(t *testing.T) {
|
||||
c.Assert(tr.MonthWide(date.Month()), qt.Equals, monthWideNorway)
|
||||
c.Assert(f.Format(date, "January"), qt.Equals, monthWideNorway)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkTimeFormatter(b *testing.B) {
|
||||
|
||||
@@ -192,5 +192,4 @@ func TestLookupEqualFold(t *testing.T) {
|
||||
v, found = LookupEqualFold(m2, "b")
|
||||
c.Assert(found, qt.IsTrue)
|
||||
c.Assert(v, qt.Equals, "bv")
|
||||
|
||||
}
|
||||
|
||||
@@ -154,7 +154,6 @@ func TestParamsSetAndMerge(t *testing.T) {
|
||||
"a": "av",
|
||||
"c": "cv",
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestParamsIsZero(t *testing.T) {
|
||||
|
||||
@@ -387,6 +387,11 @@ func ToSlashTrimLeading(s string) string {
|
||||
return strings.TrimPrefix(filepath.ToSlash(s), "/")
|
||||
}
|
||||
|
||||
// ToSlashTrimTrailing is just a filepath.ToSlash with an added / suffix trimmer.
|
||||
func ToSlashTrimTrailing(s string) string {
|
||||
return strings.TrimSuffix(filepath.ToSlash(s), "/")
|
||||
}
|
||||
|
||||
// ToSlashPreserveLeading converts the path given to a forward slash separated path
|
||||
// and preserves the leading slash if present trimming any trailing slash.
|
||||
func ToSlashPreserveLeading(s string) string {
|
||||
|
||||
@@ -163,7 +163,6 @@ func Uglify(in string) string {
|
||||
// If ParseRequestURI fails, the input is just converted to OS specific slashes and returned.
|
||||
func UrlToFilename(s string) (string, bool) {
|
||||
u, err := url.ParseRequestURI(s)
|
||||
|
||||
if err != nil {
|
||||
return filepath.FromSlash(s), false
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ line 3`
|
||||
c := qt.New(t)
|
||||
|
||||
c.Assert(collected, qt.DeepEquals, []string{"line 1\n", "line 2\n", "\n", "line 3"})
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkVisitLinesAfter(b *testing.B) {
|
||||
@@ -68,9 +67,6 @@ func BenchmarkVisitLinesAfter(b *testing.B) {
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
VisitLinesAfter(lines, func(s string) {
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,7 +80,6 @@ func ToStringSlicePreserveStringE(v any) ([]string, error) {
|
||||
default:
|
||||
return nil, fmt.Errorf("failed to convert %T to a string slice", v)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TypeToString converts v to a string if it's a valid string type.
|
||||
|
||||
@@ -45,5 +45,4 @@ func TestToDuration(t *testing.T) {
|
||||
c.Assert(ToDuration("200"), qt.Equals, 200*time.Millisecond)
|
||||
c.Assert(ToDuration("4m"), qt.Equals, 4*time.Minute)
|
||||
c.Assert(ToDuration("asdfadf"), qt.Equals, time.Duration(0))
|
||||
|
||||
}
|
||||
|
||||
@@ -107,3 +107,8 @@ type LowHigh struct {
|
||||
|
||||
// This is only used for debugging purposes.
|
||||
var InvocationCounter atomic.Int64
|
||||
|
||||
// NewTrue returns a pointer to b.
|
||||
func NewBool(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
@@ -79,5 +79,4 @@ func BenchmarkStringSort(b *testing.B) {
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
"github.com/gohugoio/hugo/common/maps"
|
||||
"github.com/gohugoio/hugo/common/paths"
|
||||
"github.com/gohugoio/hugo/common/types"
|
||||
"github.com/gohugoio/hugo/common/urls"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/gohugoio/hugo/config/privacy"
|
||||
@@ -899,6 +900,18 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Adjust Goldmark config defaults for multilingual, single-host sites.
|
||||
if len(languagesConfig) > 1 && !isMultiHost && !clone.Markup.Goldmark.DuplicateResourceFiles {
|
||||
if !clone.Markup.Goldmark.DuplicateResourceFiles {
|
||||
if clone.Markup.Goldmark.RenderHooks.Link.EnableDefault == nil {
|
||||
clone.Markup.Goldmark.RenderHooks.Link.EnableDefault = types.NewBool(true)
|
||||
}
|
||||
if clone.Markup.Goldmark.RenderHooks.Image.EnableDefault == nil {
|
||||
clone.Markup.Goldmark.RenderHooks.Image.EnableDefault = types.NewBool(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
langConfigMap[k] = clone
|
||||
case maps.ParamsMergeStrategy:
|
||||
default:
|
||||
|
||||
@@ -50,7 +50,7 @@ weight = 3
|
||||
title = "Svenska"
|
||||
weight = 4
|
||||
`
|
||||
if err := os.WriteFile(configFilename, []byte(config), 0666); err != nil {
|
||||
if err := os.WriteFile(configFilename, []byte(config), 0o666); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
d := ConfigSourceDescriptor{
|
||||
|
||||
@@ -208,7 +208,6 @@ func LoadConfigFromDir(sourceFs afero.Fs, configDir, environment string) (Provid
|
||||
}
|
||||
|
||||
return cfg, dirnames, nil
|
||||
|
||||
}
|
||||
|
||||
var keyAliases maps.KeyRenamer
|
||||
|
||||
@@ -370,7 +370,6 @@ func (c *defaultConfigProvider) SetDefaultMergeStrategy() {
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (c *defaultConfigProvider) getNestedKeyAndMap(key string, create bool) (string, maps.Params) {
|
||||
|
||||
@@ -49,7 +49,6 @@ func GetMemoryLimit() uint64 {
|
||||
if v := stringToGibabyte(mem); v > 0 {
|
||||
return v
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// There is a FreeMemory function, but as the kernel in most situations
|
||||
|
||||
@@ -43,5 +43,4 @@ func TestWhitelist(t *testing.T) {
|
||||
c.Assert(w.Accept("bar"), qt.IsTrue)
|
||||
c.Assert(w.Accept("mbar"), qt.IsFalse)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -14,11 +14,10 @@
|
||||
package deploy
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
||||
@@ -132,7 +131,6 @@ var DefaultConfig = DeployConfig{
|
||||
|
||||
// DecodeConfig creates a config from a given Hugo configuration.
|
||||
func DecodeConfig(cfg config.Provider) (DeployConfig, error) {
|
||||
|
||||
dcfg := DefaultConfig
|
||||
|
||||
if !cfg.IsSet(deploymentConfigKey) {
|
||||
|
||||
@@ -20,12 +20,10 @@ import (
|
||||
)
|
||||
|
||||
func TestExtractMinorVersionFromGoTag(t *testing.T) {
|
||||
|
||||
c := qt.New(t)
|
||||
|
||||
c.Assert(extractMinorVersionFromGoTag("go1.17"), qt.Equals, 17)
|
||||
c.Assert(extractMinorVersionFromGoTag("go1.16.7"), qt.Equals, 16)
|
||||
c.Assert(extractMinorVersionFromGoTag("go1.17beta1"), qt.Equals, 17)
|
||||
c.Assert(extractMinorVersionFromGoTag("asdfadf"), qt.Equals, -1)
|
||||
|
||||
}
|
||||
|
||||
@@ -33,9 +33,7 @@ type DuplicatesReporter interface {
|
||||
ReportDuplicates() string
|
||||
}
|
||||
|
||||
var (
|
||||
_ FilesystemUnwrapper = (*createCountingFs)(nil)
|
||||
)
|
||||
var _ FilesystemUnwrapper = (*createCountingFs)(nil)
|
||||
|
||||
func NewCreateCountingFs(fs afero.Fs) afero.Fs {
|
||||
return &createCountingFs{Fs: fs, fileCount: make(map[string]int)}
|
||||
|
||||
@@ -75,7 +75,6 @@ func TestGetGlob(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkGetGlob(b *testing.B) {
|
||||
|
||||
runBench := func(name string, cache *globCache, search string) {
|
||||
b.Run(name, func(b *testing.B) {
|
||||
g, err := GetGlob("**/foo")
|
||||
|
||||
+2
-2
@@ -41,8 +41,8 @@ Data: {{ len .Data }}|
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
//LogLevel: logg.LevelTrace,
|
||||
//Verbose: true,
|
||||
// LogLevel: logg.LevelTrace,
|
||||
// Verbose: true,
|
||||
},
|
||||
).Build()
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 88 KiB |
+3
-4
@@ -157,7 +157,7 @@ module github.com/bep/mymod
|
||||
|
||||
tempDir := os.TempDir()
|
||||
cacheDir := filepath.Join(tempDir, "hugocache")
|
||||
if err := os.MkdirAll(cacheDir, 0777); err != nil {
|
||||
if err := os.MkdirAll(cacheDir, 0o777); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg.Set("cacheDir", cacheDir)
|
||||
@@ -168,11 +168,11 @@ module github.com/bep/mymod
|
||||
|
||||
fs := afero.NewOsFs()
|
||||
|
||||
if err := afero.WriteFile(fs, filepath.Join(tempDir, "hugo.toml"), []byte(configToml), 0644); err != nil {
|
||||
if err := afero.WriteFile(fs, filepath.Join(tempDir, "hugo.toml"), []byte(configToml), 0o644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := afero.WriteFile(fs, filepath.Join(tempDir, "go.mod"), []byte(goMod), 0644); err != nil {
|
||||
if err := afero.WriteFile(fs, filepath.Join(tempDir, "go.mod"), []byte(goMod), 0o644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -181,5 +181,4 @@ module github.com/bep/mymod
|
||||
return nil, err
|
||||
}
|
||||
return conf.Base, err
|
||||
|
||||
}
|
||||
|
||||
+16
-99
@@ -48,15 +48,8 @@ title = "English Title"
|
||||
[languages.en.params.comments]
|
||||
title = "English Comments Title"
|
||||
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
enSite := b.H.Sites[0]
|
||||
b.Assert(enSite.Title(), qt.Equals, "English Title")
|
||||
@@ -97,14 +90,8 @@ weight = 2
|
||||
[languages.sv.params]
|
||||
myparam = "svParamValue"
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
enSite := b.H.Sites[0]
|
||||
svSite := b.H.Sites[1]
|
||||
@@ -157,12 +144,7 @@ baseURL = "https://example.com"
|
||||
[internal]
|
||||
running = true
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.Assert(b.H.Conf.Running(), qt.Equals, false)
|
||||
})
|
||||
@@ -236,12 +218,7 @@ p1: {{ .Site.Params.p1 }}|
|
||||
p2: {{ .Site.Params.p2 }}|
|
||||
sub: {{ .Site.Params.sub }}|
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/en/index.html", `
|
||||
title: English Title|
|
||||
@@ -987,12 +964,7 @@ params:
|
||||
mainSections: {{ site.Params.mainSections }}
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
mainSections: []
|
||||
@@ -1062,12 +1034,7 @@ Ein "Zitat" auf Deutsch.
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", "p1: p1base", "<p>A “quote” in English.</p>")
|
||||
b.AssertFileContent("public/de/index.html", "p1: p1de", "<p>Ein «Zitat» auf Deutsch.</p>")
|
||||
@@ -1129,12 +1096,7 @@ HTACCESS.
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/.htaccess", "HTACCESS")
|
||||
}
|
||||
@@ -1150,12 +1112,7 @@ LanguageCode: {{ .Site.LanguageCode }}|{{ site.Language.LanguageCode }}|
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", "LanguageCode: en-US|en-US|")
|
||||
}
|
||||
@@ -1181,12 +1138,7 @@ Home.
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", "Home.")
|
||||
|
||||
@@ -1214,12 +1166,7 @@ Foo: {{ site.Params.foo }}|
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", "Foo: |")
|
||||
})
|
||||
@@ -1295,12 +1242,7 @@ Home.
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.Assert(b.H.Configs.Base.Module.Mounts, qt.HasLen, 7)
|
||||
b.Assert(b.H.Configs.LanguageConfigSlice[0].Module.Mounts, qt.HasLen, 7)
|
||||
@@ -1321,12 +1263,7 @@ Foo.
|
||||
-- layouts/index.html --
|
||||
Home.
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/en/index.html", "Home.")
|
||||
b.AssertFileContent("public/en/foo/bar.txt", "Foo.")
|
||||
@@ -1354,12 +1291,7 @@ Foo.
|
||||
-- layouts/index.html --
|
||||
Home.
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/en/index.html", "Home.")
|
||||
b.AssertFileContent("public/en/foo/bar.txt", "Foo.")
|
||||
@@ -1387,12 +1319,7 @@ Foo.
|
||||
-- layouts/index.html --
|
||||
Home.
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", "Home.")
|
||||
b.AssertFileContent("public/foo/bar.txt", "Foo.")
|
||||
@@ -1417,12 +1344,7 @@ Home.
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.Assert(len(b.H.Sites), qt.Equals, 1)
|
||||
}
|
||||
@@ -1557,12 +1479,7 @@ List.
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileExists("public/index.html", true)
|
||||
b.AssertFileExists("public/categories/c1/index.html", true)
|
||||
|
||||
@@ -38,12 +38,7 @@ c = "c1"
|
||||
-- layouts/index.html --
|
||||
Params: {{ site.Params}}
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
Params: map[a:acp1 b:bc1 c:c1 d:dcp1]
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
package hugolib
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -63,12 +64,7 @@ outputs: ["rss"]
|
||||
---
|
||||
P3. [I'm an inline-style link](https://www.example.org)
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
P1: <p>P1. html-link: https://www.gohugo.io|</p>
|
||||
@@ -163,12 +159,7 @@ P1 Fragments: {{ .Fragments.Identifiers }}|
|
||||
{{ .Content}}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
Self Fragments: [b c z]
|
||||
@@ -179,3 +170,74 @@ Self Fragments: [d e f]
|
||||
P1 Fragments: [b c z]
|
||||
`)
|
||||
}
|
||||
|
||||
func TestDefaultRenderHooksMultilingual(t *testing.T) {
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.org"
|
||||
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT"]
|
||||
defaultContentLanguage = "nn"
|
||||
defaultContentLanguageInSubdir = true
|
||||
[markup]
|
||||
[markup.goldmark]
|
||||
duplicateResourceFiles = false
|
||||
[markup.goldmark.renderhooks]
|
||||
[markup.goldmark.renderhooks.link]
|
||||
#enableDefault = false
|
||||
[markup.goldmark.renderhooks.image]
|
||||
#enableDefault = false
|
||||
[languages]
|
||||
[languages.en]
|
||||
weight = 1
|
||||
[languages.nn]
|
||||
weight = 2
|
||||
-- content/p1/index.md --
|
||||
---
|
||||
title: "p1"
|
||||
---
|
||||
[P2](p2)
|
||||

|
||||
-- content/p2/index.md --
|
||||
---
|
||||
title: "p2"
|
||||
---
|
||||
[P1](p1)
|
||||

|
||||
-- content/p1/index.en.md --
|
||||
---
|
||||
title: "p1 en"
|
||||
---
|
||||
[P2](p2)
|
||||

|
||||
-- content/p2/index.en.md --
|
||||
---
|
||||
title: "p2 en"
|
||||
---
|
||||
[P1](p1)
|
||||

|
||||
|
||||
-- content/p1/pixel.nn.png --
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
|
||||
-- content/p2/pixel.png --
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
|
||||
-- layouts/_default/single.html --
|
||||
{{ .Title }}|{{ .Content }}|$
|
||||
|
||||
`
|
||||
|
||||
t.Run("Default multilingual", func(t *testing.T) {
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/nn/p1/index.html",
|
||||
"p1|<p><a href=\"/nn/p2/\">P2</a\n></p>", "<img alt=\"Pixel\" src=\"/nn/p1/pixel.nn.png\">")
|
||||
b.AssertFileContent("public/en/p1/index.html",
|
||||
"p1 en|<p><a href=\"/en/p2/\">P2</a\n></p>", "<img alt=\"Pixel\" src=\"/nn/p1/pixel.nn.png\">")
|
||||
})
|
||||
|
||||
t.Run("Disabled", func(t *testing.T) {
|
||||
b := Test(t, strings.ReplaceAll(files, "#enableDefault = false", "enableDefault = false"))
|
||||
|
||||
b.AssertFileContent("public/nn/p1/index.html",
|
||||
"p1|<p><a href=\"p2\">P2</a>", "<img src=\"pixel.png\" alt=\"Pixel\">")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
)
|
||||
|
||||
func TestData(t *testing.T) {
|
||||
|
||||
t.Run("with theme", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -43,14 +42,8 @@ b: {{ site.Data.b.v1 }}|
|
||||
cd: {{ site.Data.c.d.v1 }}|
|
||||
d: {{ site.Data.d.v1 }}|
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", "a: a_v1|\nb: b_v1|\ncd: c_d_v1|\nd: d_v1_theme|")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -255,12 +255,7 @@ mydata.date: {{ site.Data.mydata.date }}
|
||||
Full time: {{ $p1Date | time.Format ":time_full" }}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
Future talks: 2
|
||||
|
||||
@@ -76,12 +76,7 @@ Foo: {{< param foo >}}
|
||||
-- layouts/index.html --
|
||||
Content: {{ .Content }}|
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
<figure>
|
||||
@@ -94,6 +89,5 @@ Foo: bar
|
||||
|
||||
|
||||
`)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -657,30 +657,24 @@ min_version = 0.55.0
|
||||
func TestMountsProject(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
config := `
|
||||
|
||||
files := `
|
||||
-- config.toml --
|
||||
baseURL="https://example.org"
|
||||
|
||||
[module]
|
||||
[[module.mounts]]
|
||||
source="mycontent"
|
||||
target="content"
|
||||
|
||||
`
|
||||
b := newTestSitesBuilder(t).
|
||||
WithConfigFile("toml", config).
|
||||
WithSourceFile(filepath.Join("mycontent", "mypage.md"), `
|
||||
-- layouts/_default/single.html --
|
||||
Permalink: {{ .Permalink }}|
|
||||
-- mycontent/mypage.md --
|
||||
---
|
||||
title: "My Page"
|
||||
---
|
||||
`
|
||||
b := Test(t, files)
|
||||
|
||||
`)
|
||||
|
||||
b.Build(BuildCfg{})
|
||||
|
||||
// helpers.PrintFs(b.H.Fs.Source, "public", os.Stdout)
|
||||
|
||||
b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/")
|
||||
b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/|")
|
||||
}
|
||||
|
||||
// https://github.com/gohugoio/hugo/issues/6684
|
||||
@@ -706,25 +700,20 @@ Home: {{ .Title }}|{{ .Content }}|
|
||||
func TestSiteWithGoModButNoModules(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
c := qt.New(t)
|
||||
// We need to use the OS fs for this.
|
||||
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-no-mod")
|
||||
c.Assert(err, qt.IsNil)
|
||||
tempDir := t.TempDir()
|
||||
|
||||
cfg := config.New()
|
||||
cfg.Set("workingDir", workDir)
|
||||
cfg.Set("publishDir", "public")
|
||||
fs := hugofs.NewFromOld(hugofs.Os, cfg)
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.org"
|
||||
-- go.mod --
|
||||
|
||||
defer clean()
|
||||
`
|
||||
|
||||
b := newTestSitesBuilder(t)
|
||||
b.Fs = fs
|
||||
b := Test(t, files, TestOptWithConfig(func(cfg *IntegrationTestConfig) {
|
||||
cfg.WorkingDir = tempDir
|
||||
}))
|
||||
|
||||
b.WithWorkingDir(workDir).WithViper(cfg)
|
||||
|
||||
b.WithSourceFile("go.mod", "")
|
||||
b.Build(BuildCfg{})
|
||||
b.Build()
|
||||
}
|
||||
|
||||
// https://github.com/gohugoio/hugo/issues/6622
|
||||
@@ -783,7 +772,9 @@ P1: {{ $p1.Title }}|{{ $p1.RelPermalink }}|Filename: {{ $p1.File.Filename }}
|
||||
|
||||
// Issue 9426
|
||||
func TestMountSameSource(t *testing.T) {
|
||||
config := `baseURL = 'https://example.org/'
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = 'https://example.org/'
|
||||
languageCode = 'en-us'
|
||||
title = 'Hugo GitHub Issue #9426'
|
||||
|
||||
@@ -800,18 +791,15 @@ target = "content/resources-a"
|
||||
[[module.mounts]]
|
||||
source = "extra-content"
|
||||
target = "content/resources-b"
|
||||
-- layouts/_default/single.html --
|
||||
Single
|
||||
-- content/p1.md --
|
||||
-- extra-content/_index.md --
|
||||
-- extra-content/subdir/_index.md --
|
||||
-- extra-content/subdir/about.md --
|
||||
"
|
||||
`
|
||||
b := newTestSitesBuilder(t).WithConfigFile("toml", config)
|
||||
|
||||
b.WithContent("p1.md", "")
|
||||
|
||||
b.WithSourceFile(
|
||||
"extra-content/_index.md", "",
|
||||
"extra-content/subdir/_index.md", "",
|
||||
"extra-content/subdir/about.md", "",
|
||||
)
|
||||
|
||||
b.Build(BuildCfg{})
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/resources-a/subdir/about/index.html", "Single")
|
||||
b.AssertFileContent("public/resources-b/subdir/about/index.html", "Single")
|
||||
@@ -836,12 +824,7 @@ message: Hugo Rocks
|
||||
{{ site.Data.extra.test.message }}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", "Hugo Rocks")
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ func TestRunning(t testing.TB, files string, opts ...TestOpt) *IntegrationTestBu
|
||||
return NewIntegrationTestBuilder(cfg).Build()
|
||||
}
|
||||
|
||||
// In most cases you should not use this function directly, but the Test or TestRunning function.
|
||||
func NewIntegrationTestBuilder(conf IntegrationTestConfig) *IntegrationTestBuilder {
|
||||
// Code fences.
|
||||
conf.TxtarString = strings.ReplaceAll(conf.TxtarString, "§§§", "```")
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
func TestI18n(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
//https://github.com/gohugoio/hugo/issues/7804
|
||||
// https://github.com/gohugoio/hugo/issues/7804
|
||||
c.Run("pt-br should be case insensitive", func(c *qt.C) {
|
||||
b := newTestSitesBuilder(c)
|
||||
langCode := func() string {
|
||||
@@ -76,12 +76,10 @@ name = "foo-a"
|
||||
|
||||
menus := b.H.Sites[0].Menus()
|
||||
c.Assert(menus, qt.HasLen, 1)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestLanguageNumberFormatting(t *testing.T) {
|
||||
|
||||
b := newTestSitesBuilder(t)
|
||||
b.WithConfigFile("toml", `
|
||||
baseURL = "https://example.org"
|
||||
|
||||
+3
-18
@@ -571,12 +571,7 @@ Page IsAncestor Self: {{ $page.IsAncestor $page }}
|
||||
Page IsDescendant Self: {{ $page.IsDescendant $page}}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/tests/index.html", `
|
||||
Tests|/tests/|IsMenuCurrent = true|HasMenuCurrent = false
|
||||
@@ -609,12 +604,7 @@ Menu Item: {{ $i }}: {{ .Pre }}{{ .Name }}{{ .Post }}|{{ .URL }}|
|
||||
{{ end }}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
Menu Item: 0: <span>Home</span>|/|
|
||||
@@ -640,12 +630,7 @@ Menu Item: {{ $i }}|{{ .URL }}|
|
||||
{{ end }}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
Menu Item: 0|/foo/posts|
|
||||
|
||||
@@ -421,9 +421,20 @@ func (p *pageState) setMetaPostParams() error {
|
||||
var sitemapSet bool
|
||||
|
||||
var draft, published, isCJKLanguage *bool
|
||||
var userParams map[string]any
|
||||
for k, v := range pm.params {
|
||||
loki := strings.ToLower(k)
|
||||
|
||||
if loki == "params" {
|
||||
vv, err := maps.ToStringMapE(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userParams = vv
|
||||
delete(pm.params, k)
|
||||
continue
|
||||
}
|
||||
|
||||
if loki == "published" { // Intentionally undocumented
|
||||
vv, err := cast.ToBoolE(v)
|
||||
if err == nil {
|
||||
@@ -589,6 +600,10 @@ func (p *pageState) setMetaPostParams() error {
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range userParams {
|
||||
pm.params[strings.ToLower(k)] = v
|
||||
}
|
||||
|
||||
if !sitemapSet {
|
||||
pm.sitemap = p.s.conf.Sitemap
|
||||
}
|
||||
|
||||
@@ -469,6 +469,21 @@ func (pco *pageContentOutput) initRenderHooks() error {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if found {
|
||||
if isitp, ok := templ.(tpl.IsInternalTemplateProvider); ok && isitp.IsInternalTemplate() {
|
||||
renderHookConfig := pco.po.p.s.conf.Markup.Goldmark.RenderHooks
|
||||
switch templ.Name() {
|
||||
case "_default/_markup/render-link.html":
|
||||
if !renderHookConfig.Link.IsEnableDefault() {
|
||||
return nil, false
|
||||
}
|
||||
case "_default/_markup/render-image.html":
|
||||
if !renderHookConfig.Image.IsEnableDefault() {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return templ, found
|
||||
}
|
||||
|
||||
|
||||
@@ -698,12 +698,7 @@ title: "empty"
|
||||
|{{ .RawContent }}|
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/basic/index.html", "|**basic**|")
|
||||
b.AssertFileContent("public/empty/index.html", "! title")
|
||||
|
||||
@@ -56,7 +56,7 @@ func (c *pageFinder) getPageRef(context page.Page, ref string) (page.Page, error
|
||||
}
|
||||
|
||||
func (c *pageFinder) getPage(context page.Page, ref string) (page.Page, error) {
|
||||
n, err := c.getContentNode(context, false, filepath.ToSlash(ref))
|
||||
n, err := c.getContentNode(context, false, paths.ToSlashTrimTrailing(ref))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -413,6 +413,10 @@ title: p2
|
||||
func TestPageGetPageVariations(t *testing.T) {
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
-- content/s1/_index.md --
|
||||
---
|
||||
title: s1 section
|
||||
---
|
||||
-- content/s1/p1/index.md --
|
||||
---
|
||||
title: p1
|
||||
@@ -430,6 +434,8 @@ title: p3
|
||||
title: p2_root
|
||||
---
|
||||
-- layouts/index.html --
|
||||
/s1: {{ with .GetPage "/s1" }}{{ .Title }}{{ end }}|
|
||||
/s1/: {{ with .GetPage "/s1/" }}{{ .Title }}{{ end }}|
|
||||
/s1/p2.md: {{ with .GetPage "/s1/p2.md" }}{{ .Title }}{{ end }}|
|
||||
/s1/p2: {{ with .GetPage "/s1/p2" }}{{ .Title }}{{ end }}|
|
||||
/s1/p1/index.md: {{ with .GetPage "/s1/p1/index.md" }}{{ .Title }}{{ end }}|
|
||||
@@ -444,6 +450,8 @@ p1/index.md: {{ with .GetPage "p1/index.md" }}{{ .Title }}{{ end }}|
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
/s1: s1 section|
|
||||
/s1/: s1 section|
|
||||
/s1/p2.md: p2|
|
||||
/s1/p2: p2|
|
||||
/s1/p1/index.md: p1|
|
||||
|
||||
@@ -153,12 +153,7 @@ Len: {{ len $empty }}: Type: {{ printf "%T" $empty }}
|
||||
{{ $pag := .Paginate $pgs }}
|
||||
Len Pag: {{ len $pag.Pages }}
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", "Len: 0", "Len Pag: 0")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright 2024 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 hugolib
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFrontMatterParamsInItsOwnSection(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.org/"
|
||||
-- content/_index.md --
|
||||
+++
|
||||
title = "Home"
|
||||
[[cascade]]
|
||||
background = 'yosemite.jpg'
|
||||
[cascade.params]
|
||||
a = "home-a"
|
||||
b = "home-b"
|
||||
[cascade._target]
|
||||
kind = 'page'
|
||||
+++
|
||||
-- content/p1.md --
|
||||
---
|
||||
title: "P1"
|
||||
summary: "frontmatter.summary"
|
||||
params:
|
||||
a: "p1-a"
|
||||
summary: "params.summary"
|
||||
---
|
||||
-- layouts/_default/single.html --
|
||||
Params: {{ range $k, $v := .Params }}{{ $k }}: {{ $v }}|{{ end }}$
|
||||
Summary: {{ .Summary }}|
|
||||
`
|
||||
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html",
|
||||
"Params: a: p1-a|b: home-b|background: yosemite.jpg|draft: false|iscjklanguage: false|summary: params.summary|title: P1|$",
|
||||
"Summary: frontmatter.summary|",
|
||||
)
|
||||
}
|
||||
@@ -67,12 +67,7 @@ HasShortcode not found: {{ .HasShortcode "notfound" }}|
|
||||
Content: {{ .Content }}|
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html",
|
||||
"Fragments: [p1-h1 p2-h1 p2-h2 p2-h3 p2-withmarkdown p3-h1 p3-h2 p3-withmarkdown]|",
|
||||
@@ -118,12 +113,7 @@ JSON: {{ .Content }}
|
||||
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", "Myshort HTML")
|
||||
b.AssertFileContent("public/p1/index.json", "Myshort JSON")
|
||||
|
||||
@@ -172,12 +172,7 @@ Has other: {{ .HasShortcode "other" }}
|
||||
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html",
|
||||
`
|
||||
@@ -213,12 +208,7 @@ title: "P1"
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `TableOfContents`)
|
||||
}
|
||||
|
||||
@@ -916,12 +916,7 @@ title: "p1"
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
<x
|
||||
@@ -957,12 +952,7 @@ title: "p1"
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", "<ol>\n<li>\n<p>List 1</p>\n<ol>\n<li>Item Mark1 1</li>\n<li>Item Mark1 2</li>\n<li>Item Mark2 1</li>\n<li>Item Mark2 2\n<ol>\n<li>Item Mark2 2-1</li>\n</ol>\n</li>\n<li>Item Mark2 3</li>\n</ol>\n</li>\n</ol>")
|
||||
}
|
||||
@@ -987,12 +977,7 @@ echo "foo";
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", "<pre><code>echo "foo";\n</code></pre>")
|
||||
}
|
||||
@@ -1023,12 +1008,7 @@ title: "p1"
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
<pre><code> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">line 1<span class="p">;</span>
|
||||
|
||||
+3
-18
@@ -436,12 +436,7 @@ MainSections Site method: {{ site.MainSections }}|
|
||||
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
MainSections Params: [a b]|
|
||||
@@ -469,12 +464,7 @@ MainSections Site method: {{ site.MainSections }}|
|
||||
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
MainSections Params: [a b]|
|
||||
@@ -497,12 +487,7 @@ MainSections Site method: {{ site.MainSections }}|
|
||||
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
MainSections Params: [mysect]|
|
||||
|
||||
@@ -128,12 +128,7 @@ SectionsEntries: {{ .SectionsEntries }}
|
||||
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/withfile/index.html", "SectionsEntries: [withfile]")
|
||||
b.AssertFileContent("public/withoutfile/index.html", "SectionsEntries: [withoutfile]")
|
||||
|
||||
+3
-18
@@ -39,12 +39,7 @@ title: doc2
|
||||
Doc2
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/sitemap.xml", " <loc>https://example.com/sect/doc1/</loc>", "doc2")
|
||||
}
|
||||
@@ -81,12 +76,7 @@ title: doc2
|
||||
Doc2
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/sitemap.xml", "<loc>https://example.com/en/sitemap.xml</loc>", "<loc>https://example.com/nn/sitemap.xml</loc>")
|
||||
b.AssertFileContent("public/en/sitemap.xml", " <loc>https://example.com/sect/doc1/</loc>", "doc2")
|
||||
@@ -109,12 +99,7 @@ outputs: [ "html", "amp" ]
|
||||
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
// Should link to the HTML version.
|
||||
b.AssertFileContent("public/sitemap.xml", " <loc>https://example.com/blog/html-amp/</loc>")
|
||||
|
||||
@@ -730,12 +730,7 @@ tags_weight: 40
|
||||
---
|
||||
`
|
||||
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `:/p1/|/p3/|/p2/|:`)
|
||||
}
|
||||
|
||||
@@ -44,12 +44,7 @@ l1: {{ i18n "l1" }}|l2: {{ i18n "l2" }}|l3: {{ i18n "l3" }}
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
l1: l1main|l2: l2main|l3: l3theme
|
||||
@@ -92,12 +87,7 @@ i18n: {{ i18n "a" . }}|
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
i18n: Reading time: 3|
|
||||
@@ -131,12 +121,7 @@ title: home_es
|
||||
---
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/es/index.html", `home_es_gato`)
|
||||
b.AssertFileContent("public/fr/index.html", `home_fr_gato`)
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
)
|
||||
|
||||
func TestCollator(t *testing.T) {
|
||||
|
||||
c := qt.New(t)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
@@ -43,7 +42,6 @@ func TestCollator(t *testing.T) {
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkCollator(b *testing.B) {
|
||||
@@ -75,5 +73,4 @@ func BenchmarkCollator(b *testing.B) {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -234,5 +234,4 @@ func TestResetError(t *testing.T) {
|
||||
r = true
|
||||
_, err = i.Do(context.Background())
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
}
|
||||
|
||||
+9
-32
@@ -185,42 +185,15 @@ func TestRace() error {
|
||||
|
||||
// Run gofmt linter
|
||||
func Fmt() error {
|
||||
if !isGoLatest() {
|
||||
if !isGoLatest() && !isUnix() {
|
||||
return nil
|
||||
}
|
||||
pkgs, err := hugoPackages()
|
||||
s, err := sh.Output("./check_gofmt.sh")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
failed := false
|
||||
first := true
|
||||
for _, pkg := range pkgs {
|
||||
files, err := filepath.Glob(filepath.Join(pkg, "*.go"))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, f := range files {
|
||||
// gofmt doesn't exit with non-zero when it finds unformatted code
|
||||
// so we have to explicitly look for output, and if we find any, we
|
||||
// should fail this target.
|
||||
s, err := sh.Output("gofmt", "-l", f)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: running gofmt on %q: %v\n", f, err)
|
||||
failed = true
|
||||
}
|
||||
if s != "" {
|
||||
if first {
|
||||
fmt.Println("The following files are not gofmt'ed:")
|
||||
first = false
|
||||
}
|
||||
failed = true
|
||||
fmt.Println(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
if failed {
|
||||
return errors.New("improperly formatted go files")
|
||||
fmt.Println(s)
|
||||
return fmt.Errorf("gofmt needs to be run: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -332,6 +305,10 @@ func isGoLatest() bool {
|
||||
return strings.Contains(runtime.Version(), "1.21")
|
||||
}
|
||||
|
||||
func isUnix() bool {
|
||||
return runtime.GOOS != "windows"
|
||||
}
|
||||
|
||||
func isCI() bool {
|
||||
return os.Getenv("CI") != ""
|
||||
}
|
||||
|
||||
+6
-40
@@ -87,13 +87,7 @@ echo "l8";
|
||||
§§§
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
Goat SVG:<svg class='diagram'
|
||||
@@ -152,13 +146,7 @@ fmt.Println("Hello, World!");
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html",
|
||||
"Inner: |<span class=\"line\"><span class=\"cl\"><span class=\"nx\">fmt</span><span class=\"p\">.</span><span class=\"nf\">Println</span><span class=\"p\">(</span><span class=\"s\">"Hello, World!"</span><span class=\"p\">);</span></span></span>|",
|
||||
@@ -188,13 +176,7 @@ title: "p1"
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
# Issue 9627: For the Position in code blocks we try to match the .Inner with the original source. This isn't always possible.
|
||||
@@ -223,13 +205,7 @@ echo "p1";
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", "|echo \"p1\";|")
|
||||
}
|
||||
@@ -257,12 +233,7 @@ Position: {{ .Position | safeHTML }}
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", filepath.FromSlash("Position: \"/content/p1.md:7:1\""))
|
||||
}
|
||||
@@ -290,12 +261,7 @@ Hello, World!
|
||||
Attributes: {{ .Attributes }}|Type: {{ .Type }}|
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", "<h2 id=\"issue-10118\">Issue 10118</h2>\nAttributes: map[foo:bar]|Type: |")
|
||||
}
|
||||
@@ -73,10 +73,39 @@ var Default = Config{
|
||||
|
||||
// Config configures Goldmark.
|
||||
type Config struct {
|
||||
DuplicateResourceFiles bool
|
||||
Renderer Renderer
|
||||
Parser Parser
|
||||
Extensions Extensions
|
||||
DuplicateResourceFiles bool
|
||||
RenderHooks RenderHooks
|
||||
}
|
||||
|
||||
// RenderHooks contains configuration for Goldmark render hooks.
|
||||
type RenderHooks struct {
|
||||
Image ImageRenderHook
|
||||
Link LinkRenderHook
|
||||
}
|
||||
|
||||
// ImageRenderHook contains configuration for the image render hook.
|
||||
type ImageRenderHook struct {
|
||||
// Enable the default image render hook.
|
||||
// We need to know if it is set or not, hence the pointer.
|
||||
EnableDefault *bool
|
||||
}
|
||||
|
||||
func (h ImageRenderHook) IsEnableDefault() bool {
|
||||
return h.EnableDefault != nil && *h.EnableDefault
|
||||
}
|
||||
|
||||
// LinkRenderHook contains configuration for the link render hook.
|
||||
type LinkRenderHook struct {
|
||||
// Disable the default image render hook.
|
||||
// We need to know if it is set or not, hence the pointer.
|
||||
EnableDefault *bool
|
||||
}
|
||||
|
||||
func (h LinkRenderHook) IsEnableDefault() bool {
|
||||
return h.EnableDefault != nil && *h.EnableDefault
|
||||
}
|
||||
|
||||
type Extensions struct {
|
||||
|
||||
+11
-78
@@ -50,13 +50,7 @@ foo
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
<h2 class="a" id="heading">
|
||||
@@ -85,13 +79,7 @@ title: "p1"
|
||||
>{{ .Text | safeHTML }}</h{{ .Level }}>
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
<h2 data-foo="bar" id="heading">Heading</h2>
|
||||
@@ -111,13 +99,7 @@ title: "p1"
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
class="a < b"
|
||||
@@ -141,13 +123,7 @@ safeHTML: |{{- range $k, $v := .Attributes -}}{{ $k }}: {{ $v | safeHTML }}|{{ e
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
plain: |class: Smith & Wesson|id: heading-attribute-which-needs-escaping|
|
||||
@@ -178,13 +154,7 @@ title: "p1"
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html",
|
||||
"<h2 id=\"hello-testhttpsexamplecom\">\n Hello <a href=\"https://example.com\">Test</a>\n\n <a class=\"anchor\" href=\"#hello-testhttpsexamplecom\">#</a>\n</h2>",
|
||||
@@ -252,12 +222,7 @@ LINE8
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html",
|
||||
"<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">LINE1\n</span></span></code></pre></div>",
|
||||
@@ -397,7 +362,6 @@ FENCE
|
||||
|
||||
runBenchmark(files, b)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// Iisse #8959
|
||||
@@ -406,7 +370,6 @@ func TestHookInfiniteRecursion(t *testing.T) {
|
||||
|
||||
for _, renderFunc := range []string{"markdownify", ".Page.RenderString"} {
|
||||
t.Run(renderFunc, func(t *testing.T) {
|
||||
|
||||
files := `
|
||||
-- config.toml --
|
||||
-- layouts/_default/_markup/render-link.html --
|
||||
@@ -436,11 +399,8 @@ a@b.com
|
||||
|
||||
b.Assert(err, qt.IsNotNil)
|
||||
b.Assert(err.Error(), qt.Contains, "text is already rendered, repeating it may cause infinite recursion")
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Issue 9594
|
||||
@@ -460,12 +420,7 @@ title: "p1"
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", `
|
||||
<img src="b.jpg" alt=""a"">
|
||||
@@ -476,7 +431,6 @@ func TestLinkifyProtocol(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
runTest := func(protocol string, withHook bool) *hugolib.IntegrationTestBuilder {
|
||||
|
||||
files := `
|
||||
-- config.toml --
|
||||
[markup.goldmark]
|
||||
@@ -507,7 +461,6 @@ Link https procol: https://www.example.org
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
|
||||
}
|
||||
|
||||
for _, withHook := range []bool{false, true} {
|
||||
@@ -564,12 +517,7 @@ a <!-- b --> c
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContentExact("public/p1/index.html",
|
||||
// Issue 9650
|
||||
@@ -621,12 +569,7 @@ sc3_begin|{{ .Inner }}|sc3_end
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContentExact("public/p1/index.html",
|
||||
// Issue #7332
|
||||
@@ -657,12 +600,7 @@ title: "p1"
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContentExact("public/p1/index.html", "<p>:x:</p>")
|
||||
}
|
||||
@@ -680,12 +618,7 @@ title: "p1"
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContentExact("public/p1/index.html", "<p>:x:</p>")
|
||||
}
|
||||
+4
-28
@@ -45,13 +45,7 @@ This is an inline image: . Some more text.
|
||||
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}|{{ .Ordinal }}" />
|
||||
{{ end }}
|
||||
`
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html",
|
||||
"This is an inline image: \n\t<img src=\"/inline.jpg\" alt=\"Inline Image|0\" />\n. Some more text.</p>",
|
||||
@@ -70,13 +64,7 @@ This is an inline image: . Some more text.
|
||||
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" />
|
||||
{{ end }}
|
||||
`
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html",
|
||||
"This is an inline image: \n\t<img src=\"/inline.jpg\" alt=\"Inline Image\" />\n. Some more text.</p>",
|
||||
@@ -86,26 +74,14 @@ This is an inline image: . Some more text.
|
||||
|
||||
t.Run("No Hook, no wrap", func(t *testing.T) {
|
||||
files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false")
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", "<p>This is an inline image: <img src=\"/inline.jpg\" alt=\"Inline Image\">. Some more text.</p>\n<img src=\"/block.jpg\" alt=\"Block Image\" class=\"b\">")
|
||||
})
|
||||
|
||||
t.Run("No Hook, wrap", func(t *testing.T) {
|
||||
files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true")
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html", "<p class=\"b\"><img src=\"/block.jpg\" alt=\"Block Image\"></p>")
|
||||
})
|
||||
@@ -71,7 +71,5 @@ func (t *Transformer) Transform(doc *ast.Document, reader text.Reader, pctx pars
|
||||
}
|
||||
|
||||
return ast.WalkContinue, nil
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (a *attrParser) Continue(node ast.Node, reader text.Reader, pc parser.Conte
|
||||
func (a *attrParser) Open(parent ast.Node, reader text.Reader, pc parser.Context) (ast.Node, parser.State) {
|
||||
if attrs, ok := parser.ParseAttributes(reader); ok {
|
||||
// add attributes
|
||||
var node = &attributesBlock{
|
||||
node := &attributesBlock{
|
||||
BaseBlock: ast.BaseBlock{},
|
||||
}
|
||||
for _, attr := range attrs {
|
||||
@@ -95,7 +95,7 @@ func (a *attributesBlock) Kind() ast.NodeKind {
|
||||
type transformer struct{}
|
||||
|
||||
func (a *transformer) Transform(node *ast.Document, reader text.Reader, pc parser.Context) {
|
||||
var attributes = make([]ast.Node, 0, 500)
|
||||
attributes := make([]ast.Node, 0, 500)
|
||||
ast.Walk(node, func(node ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||
if entering && node.Kind() == kindAttributesBlock {
|
||||
// Attributes for fenced code blocks are handled in their own extension,
|
||||
|
||||
+2
-14
@@ -67,13 +67,7 @@ HighlightCodeBlock: Wrapped:{{ $result.Wrapped }}|Inner:{{ $result.Inner }}
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/p1/index.html",
|
||||
"Inline:<code class=\"code-inline language-emacs\"><span class=\"p\">(</span><span class=\"nf\">message</span> <span class=\"s\">"this highlight shortcode"</span><span class=\"p\">)</span></code>:End.",
|
||||
@@ -103,13 +97,7 @@ xəx := 0
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: false,
|
||||
},
|
||||
).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
<span class="nx">xəx</span>
|
||||
@@ -13,7 +13,8 @@ import (
|
||||
func ExternallyRenderContent(
|
||||
cfg converter.ProviderConfig,
|
||||
ctx converter.DocumentContext,
|
||||
content []byte, binaryName string, args []string) ([]byte, error) {
|
||||
content []byte, binaryName string, args []string,
|
||||
) ([]byte, error) {
|
||||
logger := cfg.Logger
|
||||
|
||||
if strings.Contains(binaryName, "/") {
|
||||
|
||||
@@ -83,7 +83,5 @@ func TestConfig(t *testing.T) {
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(conf.Goldmark.Extensions.Typographer.Disable, qt.Equals, false)
|
||||
c.Assert(conf.Goldmark.Extensions.Typographer.Ellipsis, qt.Equals, "…")
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ import (
|
||||
// Provider is the package entry point.
|
||||
var Provider converter.ProviderProvider = provider{}
|
||||
|
||||
type provider struct {
|
||||
}
|
||||
type provider struct{}
|
||||
|
||||
func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error) {
|
||||
return converter.NewProvider("pandoc", func(ctx converter.DocumentContext) (converter.Converter, error) {
|
||||
|
||||
@@ -30,8 +30,7 @@ import (
|
||||
// Provider is the package entry point.
|
||||
var Provider converter.ProviderProvider = provider{}
|
||||
|
||||
type provider struct {
|
||||
}
|
||||
type provider struct{}
|
||||
|
||||
func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error) {
|
||||
return converter.NewProvider("rst", func(ctx converter.DocumentContext) (converter.Converter, error) {
|
||||
|
||||
@@ -186,7 +186,6 @@ func TestTocMisc(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkToc(b *testing.B) {
|
||||
|
||||
newTocs := func(n int) []*Fragments {
|
||||
var tocs []*Fragments
|
||||
for i := 0; i < n; i++ {
|
||||
@@ -216,5 +215,4 @@ func BenchmarkToc(b *testing.B) {
|
||||
toc.ToHTML(1, -1, false)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
+43
-45
@@ -51,58 +51,56 @@ type BuiltinTypes struct {
|
||||
OctetType Type
|
||||
}
|
||||
|
||||
var (
|
||||
Builtin = BuiltinTypes{
|
||||
CalendarType: Type{Type: "text/calendar"},
|
||||
CSSType: Type{Type: "text/css"},
|
||||
SCSSType: Type{Type: "text/x-scss"},
|
||||
SASSType: Type{Type: "text/x-sass"},
|
||||
CSVType: Type{Type: "text/csv"},
|
||||
HTMLType: Type{Type: "text/html"},
|
||||
JavascriptType: Type{Type: "text/javascript"},
|
||||
TypeScriptType: Type{Type: "text/typescript"},
|
||||
TSXType: Type{Type: "text/tsx"},
|
||||
JSXType: Type{Type: "text/jsx"},
|
||||
var Builtin = BuiltinTypes{
|
||||
CalendarType: Type{Type: "text/calendar"},
|
||||
CSSType: Type{Type: "text/css"},
|
||||
SCSSType: Type{Type: "text/x-scss"},
|
||||
SASSType: Type{Type: "text/x-sass"},
|
||||
CSVType: Type{Type: "text/csv"},
|
||||
HTMLType: Type{Type: "text/html"},
|
||||
JavascriptType: Type{Type: "text/javascript"},
|
||||
TypeScriptType: Type{Type: "text/typescript"},
|
||||
TSXType: Type{Type: "text/tsx"},
|
||||
JSXType: Type{Type: "text/jsx"},
|
||||
|
||||
JSONType: Type{Type: "application/json"},
|
||||
WebAppManifestType: Type{Type: "application/manifest+json"},
|
||||
RSSType: Type{Type: "application/rss+xml"},
|
||||
XMLType: Type{Type: "application/xml"},
|
||||
SVGType: Type{Type: "image/svg+xml"},
|
||||
TextType: Type{Type: "text/plain"},
|
||||
TOMLType: Type{Type: "application/toml"},
|
||||
YAMLType: Type{Type: "application/yaml"},
|
||||
JSONType: Type{Type: "application/json"},
|
||||
WebAppManifestType: Type{Type: "application/manifest+json"},
|
||||
RSSType: Type{Type: "application/rss+xml"},
|
||||
XMLType: Type{Type: "application/xml"},
|
||||
SVGType: Type{Type: "image/svg+xml"},
|
||||
TextType: Type{Type: "text/plain"},
|
||||
TOMLType: Type{Type: "application/toml"},
|
||||
YAMLType: Type{Type: "application/yaml"},
|
||||
|
||||
// Common image types
|
||||
PNGType: Type{Type: "image/png"},
|
||||
JPEGType: Type{Type: "image/jpeg"},
|
||||
GIFType: Type{Type: "image/gif"},
|
||||
TIFFType: Type{Type: "image/tiff"},
|
||||
BMPType: Type{Type: "image/bmp"},
|
||||
WEBPType: Type{Type: "image/webp"},
|
||||
// Common image types
|
||||
PNGType: Type{Type: "image/png"},
|
||||
JPEGType: Type{Type: "image/jpeg"},
|
||||
GIFType: Type{Type: "image/gif"},
|
||||
TIFFType: Type{Type: "image/tiff"},
|
||||
BMPType: Type{Type: "image/bmp"},
|
||||
WEBPType: Type{Type: "image/webp"},
|
||||
|
||||
// Common font types
|
||||
TrueTypeFontType: Type{Type: "font/ttf"},
|
||||
OpenTypeFontType: Type{Type: "font/otf"},
|
||||
// Common font types
|
||||
TrueTypeFontType: Type{Type: "font/ttf"},
|
||||
OpenTypeFontType: Type{Type: "font/otf"},
|
||||
|
||||
// Common document types
|
||||
PDFType: Type{Type: "application/pdf"},
|
||||
MarkdownType: Type{Type: "text/markdown"},
|
||||
// Common document types
|
||||
PDFType: Type{Type: "application/pdf"},
|
||||
MarkdownType: Type{Type: "text/markdown"},
|
||||
|
||||
// Common video types
|
||||
AVIType: Type{Type: "video/x-msvideo"},
|
||||
MPEGType: Type{Type: "video/mpeg"},
|
||||
MP4Type: Type{Type: "video/mp4"},
|
||||
OGGType: Type{Type: "video/ogg"},
|
||||
WEBMType: Type{Type: "video/webm"},
|
||||
GPPType: Type{Type: "video/3gpp"},
|
||||
// Common video types
|
||||
AVIType: Type{Type: "video/x-msvideo"},
|
||||
MPEGType: Type{Type: "video/mpeg"},
|
||||
MP4Type: Type{Type: "video/mp4"},
|
||||
OGGType: Type{Type: "video/ogg"},
|
||||
WEBMType: Type{Type: "video/webm"},
|
||||
GPPType: Type{Type: "video/3gpp"},
|
||||
|
||||
// Web assembly.
|
||||
WasmType: Type{Type: "application/wasm"},
|
||||
// Web assembly.
|
||||
WasmType: Type{Type: "application/wasm"},
|
||||
|
||||
OctetType: Type{Type: "application/octet-stream"},
|
||||
}
|
||||
)
|
||||
OctetType: Type{Type: "application/octet-stream"},
|
||||
}
|
||||
|
||||
var defaultMediaTypesConfig = map[string]any{
|
||||
"text/calendar": map[string]any{"suffixes": []string{"ics"}},
|
||||
|
||||
@@ -184,7 +184,6 @@ func TestDecodeConfigDecimalIsNowPrecision(t *testing.T) {
|
||||
conf := testconfig.GetTestConfigs(nil, v).Base.Minify
|
||||
|
||||
c.Assert(conf.Tdewolff.CSS.Precision, qt.Equals, 3)
|
||||
|
||||
}
|
||||
|
||||
// Issue 9456
|
||||
@@ -209,7 +208,7 @@ func TestDecodeConfigKeepWhitespace(t *testing.T) {
|
||||
KeepDocumentTags: true,
|
||||
KeepEndTags: false,
|
||||
KeepQuotes: false,
|
||||
KeepWhitespace: false},
|
||||
KeepWhitespace: false,
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
+7
-7
@@ -18,6 +18,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -46,8 +47,6 @@ import (
|
||||
|
||||
"github.com/gohugoio/hugo/common/hugio"
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
@@ -199,7 +198,7 @@ func (c *Client) Vendor() error {
|
||||
if err := c.rmVendorDir(vendorDir); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.fs.MkdirAll(vendorDir, 0755); err != nil {
|
||||
if err := c.fs.MkdirAll(vendorDir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -260,7 +259,7 @@ func (c *Client) Vendor() error {
|
||||
} else {
|
||||
targetDir := filepath.Dir(targetFilename)
|
||||
|
||||
if err := c.fs.MkdirAll(targetDir, 0755); err != nil {
|
||||
if err := c.fs.MkdirAll(targetDir, 0o755); err != nil {
|
||||
return fmt.Errorf("failed to make target dir: %w", err)
|
||||
}
|
||||
|
||||
@@ -303,7 +302,7 @@ func (c *Client) Vendor() error {
|
||||
}
|
||||
|
||||
if modulesContent.Len() > 0 {
|
||||
if err := afero.WriteFile(c.fs, filepath.Join(vendorDir, vendorModulesFilename), modulesContent.Bytes(), 0666); err != nil {
|
||||
if err := afero.WriteFile(c.fs, filepath.Join(vendorDir, vendorModulesFilename), modulesContent.Bytes(), 0o666); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -558,7 +557,7 @@ func (c *Client) rewriteGoMod(name string, isGoMod map[string]bool) error {
|
||||
return err
|
||||
}
|
||||
if data != nil {
|
||||
if err := afero.WriteFile(c.fs, filepath.Join(c.ccfg.WorkingDir, name), data, 0666); err != nil {
|
||||
if err := afero.WriteFile(c.fs, filepath.Join(c.ccfg.WorkingDir, name), data, 0o666); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -636,7 +635,8 @@ func (c *Client) rmVendorDir(vendorDir string) error {
|
||||
func (c *Client) runGo(
|
||||
ctx context.Context,
|
||||
stdout io.Writer,
|
||||
args ...string) error {
|
||||
args ...string,
|
||||
) error {
|
||||
if c.goBinaryStatus != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ func (m ModulesConfig) HasConfigFile() bool {
|
||||
func (m *ModulesConfig) setActiveMods(logger loggers.Logger) error {
|
||||
for _, mod := range m.AllModules {
|
||||
if !mod.Config().HugoVersion.IsValid() {
|
||||
logger.Warnf(`Module %q is not compatible with this Hugo version; run "hugo mod graph" for more information.`, mod.Path())
|
||||
logger.Warnf(`Module %q is not compatible with this Hugo version: %s; run "hugo mod graph" for more information.`, mod.Path(), mod.Config().HugoVersion)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,6 @@ lang="en"
|
||||
c.Assert(imp.Mounts[1].Source, qt.Equals, "src/markdown/blog")
|
||||
c.Assert(imp.Mounts[1].Target, qt.Equals, "content/blog")
|
||||
c.Assert(imp.Mounts[1].Lang, qt.Equals, "en")
|
||||
|
||||
})
|
||||
|
||||
c.Run("Replacements", func(c *qt.C) {
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
var _ Module = (*moduleAdapter)(nil)
|
||||
|
||||
type Module interface {
|
||||
|
||||
// Optional config read from the configFilename above.
|
||||
Cfg() config.Provider
|
||||
|
||||
@@ -157,7 +156,6 @@ func (m *moduleAdapter) Time() time.Time {
|
||||
}
|
||||
|
||||
return *m.gomod.Time
|
||||
|
||||
}
|
||||
|
||||
func (m *moduleAdapter) Watch() bool {
|
||||
|
||||
@@ -35,6 +35,7 @@ func (entry menuCacheEntry) matches(menuList []Menu) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// newMenuCache creates a new menuCache instance.
|
||||
func newMenuCache() *menuCache {
|
||||
return &menuCache{m: make(map[string][]menuCacheEntry)}
|
||||
}
|
||||
@@ -44,31 +45,23 @@ type menuCache struct {
|
||||
m map[string][]menuCacheEntry
|
||||
}
|
||||
|
||||
// menuEqual checks if two menus are equal.
|
||||
func menuEqual(m1, m2 Menu) bool {
|
||||
if m1 == nil && m2 == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if m1 == nil || m2 == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(m1) != len(m2) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(m1) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for i := 0; i < len(m1); i++ {
|
||||
for i := range m1 {
|
||||
if m1[i] != m2[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// get retrieves a menu from the cache based on the provided key and menuLists.
|
||||
// If the menu is not found, it applies the provided function and caches the result.
|
||||
func (c *menuCache) get(key string, apply func(m Menu), menuLists ...Menu) (Menu, bool) {
|
||||
return c.getP(key, func(m *Menu) {
|
||||
if apply != nil {
|
||||
@@ -77,6 +70,7 @@ func (c *menuCache) get(key string, apply func(m Menu), menuLists ...Menu) (Menu
|
||||
}, menuLists...)
|
||||
}
|
||||
|
||||
// getP is similar to get but also returns a boolean indicating whether the menu was found in the cache.
|
||||
func (c *menuCache) getP(key string, apply func(m *Menu), menuLists ...Menu) (Menu, bool) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
@@ -78,7 +78,7 @@ func PageMenusFromPage(p Page) (PageMenus, error) {
|
||||
return pm, nil
|
||||
}
|
||||
|
||||
var wrapErr = func(err error) error {
|
||||
wrapErr := func(err error) error {
|
||||
return fmt.Errorf("unable to process menus for page %q: %w", p.Path(), err)
|
||||
}
|
||||
|
||||
@@ -109,7 +109,8 @@ func PageMenusFromPage(p Page) (PageMenus, error) {
|
||||
func NewMenuQueryProvider(
|
||||
pagem PageMenusGetter,
|
||||
sitem MenusGetter,
|
||||
p Page) MenuQueryProvider {
|
||||
p Page,
|
||||
) MenuQueryProvider {
|
||||
return &pageMenus{
|
||||
p: p,
|
||||
pagem: pagem,
|
||||
|
||||
@@ -41,7 +41,6 @@ func createLayoutExamples() any {
|
||||
name string
|
||||
d layouts.LayoutDescriptor
|
||||
}{
|
||||
|
||||
// Taxonomy layouts.LayoutDescriptor={categories category taxonomy en false Type Section
|
||||
{"Single page in \"posts\" section", layouts.LayoutDescriptor{Kind: "page", Type: "posts", OutputFormatName: "html", Suffix: "html"}},
|
||||
{"Base template for single page in \"posts\" section", layouts.LayoutDescriptor{Baseof: true, Kind: "page", Type: "posts", OutputFormatName: "html", Suffix: "html"}},
|
||||
|
||||
@@ -953,7 +953,6 @@ func TestLayout(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -69,7 +69,6 @@ func TestDefaultTypes(t *testing.T) {
|
||||
c.Assert(CalendarFormat.IsHTML, qt.Equals, false)
|
||||
|
||||
c.Assert(len(DefaultFormats), qt.Equals, 11)
|
||||
|
||||
}
|
||||
|
||||
func TestGetFormatByName(t *testing.T) {
|
||||
|
||||
@@ -56,23 +56,26 @@ func TestUnmarshalXML(t *testing.T) {
|
||||
"guid": "https://example.com/2021/11/30/example-title/",
|
||||
"link": "https://example.com/2021/11/30/example-title/",
|
||||
"pubDate": "Tue, 30 Nov 2021 15:00:00 +0000",
|
||||
"title": "Example title"},
|
||||
"title": "Example title",
|
||||
},
|
||||
"language": "en-us",
|
||||
"lastBuildDate": "Fri, 08 Jan 2021 14:44:10 +0000",
|
||||
"link": []any{"https://example.com/", map[string]any{
|
||||
"-href": "https://example.com/feed.xml",
|
||||
"-rel": "self",
|
||||
"-type": "application/rss+xml"}},
|
||||
"-type": "application/rss+xml",
|
||||
}},
|
||||
"title": "Example feed",
|
||||
}}
|
||||
},
|
||||
}
|
||||
|
||||
d := Default
|
||||
|
||||
m, err := d.Unmarshal([]byte(xmlDoc), XML)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(m, qt.DeepEquals, expect)
|
||||
|
||||
}
|
||||
|
||||
func TestUnmarshalToMap(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
|
||||
@@ -46,5 +46,4 @@ func TestItemValTyped(t *testing.T) {
|
||||
c.Assert(Item{low: 0, high: len(source)}.ValTyped(source), qt.Equals, "truex")
|
||||
source = []byte("xtrue")
|
||||
c.Assert(Item{low: 0, high: len(source)}.ValTyped(source), qt.Equals, "xtrue")
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ type lexerShortcodeState struct {
|
||||
elementStepNum int // step number in element
|
||||
paramElements int // number of elements (name + value = 2) found first
|
||||
openShortcodes map[string]bool // set of shortcodes in open state
|
||||
|
||||
}
|
||||
|
||||
// Shortcode syntax
|
||||
|
||||
@@ -466,7 +466,6 @@ func parseStartTag(s string) string {
|
||||
}
|
||||
|
||||
return s
|
||||
|
||||
}
|
||||
|
||||
// isClosedByTag reports whether b ends with a closing tag for tagName.
|
||||
@@ -523,7 +522,6 @@ LOOP:
|
||||
}
|
||||
|
||||
return bytes.EqualFold(tagName, b[lo:hi])
|
||||
|
||||
}
|
||||
|
||||
func isSpace(b byte) bool {
|
||||
|
||||
@@ -86,7 +86,8 @@ func TestClassCollector(t *testing.T) {
|
||||
}">
|
||||
</div>
|
||||
</body>`, f("body div", "class1 class2 class3", "")},
|
||||
{"AlpineJS bind 2", `<div x-bind:class="{ 'bg-black': filter.checked }" class="inline-block mr-1 mb-2 rounded bg-gray-300 px-2 py-2">FOO</div>`,
|
||||
{
|
||||
"AlpineJS bind 2", `<div x-bind:class="{ 'bg-black': filter.checked }" class="inline-block mr-1 mb-2 rounded bg-gray-300 px-2 py-2">FOO</div>`,
|
||||
f("div", "bg-black bg-gray-300 inline-block mb-2 mr-1 px-2 py-2 rounded", ""),
|
||||
},
|
||||
{"AlpineJS bind 3", `<div x-bind:class="{ 'text-gray-800': !checked, 'text-white': checked }"></div>`, f("div", "text-gray-800 text-white", "")},
|
||||
@@ -130,7 +131,6 @@ func TestClassCollector(t *testing.T) {
|
||||
<div id="b" class="foo">d</div>`, f("div form", "foo", "a b")},
|
||||
{"Big input, multibyte runes", strings.Repeat(`神真美好 `, rnd.Intn(500)+1) + "<div id=\"神真美好\" class=\"foo\">" + strings.Repeat(`神真美好 `, rnd.Intn(100)+1) + " <span>神真美好</span>", f("div span", "foo", "神真美好")},
|
||||
} {
|
||||
|
||||
for _, variant := range []struct {
|
||||
minify bool
|
||||
}{
|
||||
@@ -161,7 +161,6 @@ func TestClassCollector(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEndsWithTag(t *testing.T) {
|
||||
@@ -190,7 +189,6 @@ func TestEndsWithTag(t *testing.T) {
|
||||
c.Assert(got, qt.Equals, test.expect)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkElementsCollectorWriter(b *testing.B) {
|
||||
@@ -276,6 +274,5 @@ func BenchmarkElementsCollectorWriterPre(b *testing.B) {
|
||||
))
|
||||
for i := 0; i < b.N; i++ {
|
||||
fmt.Fprint(w, benchHTML)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,6 @@ func TestCardinalityThreshold(t *testing.T) {
|
||||
c.Assert(hasKeyword("tags", "b"), qt.Equals, false)
|
||||
c.Assert(hasKeyword("tags", "d"), qt.Equals, true)
|
||||
c.Assert(hasKeyword("keywords", "b"), qt.Equals, true)
|
||||
|
||||
}
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
|
||||
@@ -114,11 +114,7 @@ Content: {{ .Content }}
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
}).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
expect := `
|
||||
P1 Fragments: [p1-title]
|
||||
@@ -50,7 +50,6 @@ func ColorToHexString(c color.Color) string {
|
||||
r, g, b, a := c.RGBA()
|
||||
rgba := color.RGBA{uint8(r), uint8(g), uint8(b), uint8(a)}
|
||||
return fmt.Sprintf("#%.2x%.2x%.2x", rgba.R, rgba.G, rgba.B)
|
||||
|
||||
}
|
||||
|
||||
func hexStringToColor(s string) (color.Color, error) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
)
|
||||
|
||||
func TestGroupByLocalizedDate(t *testing.T) {
|
||||
|
||||
files := `
|
||||
-- config.toml --
|
||||
defaultContentLanguage = 'en'
|
||||
@@ -72,7 +71,6 @@ date: "2020-02-01"
|
||||
}
|
||||
|
||||
func TestPagesSortCollation(t *testing.T) {
|
||||
|
||||
files := `
|
||||
-- config.toml --
|
||||
defaultContentLanguage = 'en'
|
||||
@@ -166,12 +164,7 @@ RelPermalink: {{ .RelPermalink }}
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
}).Build()
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/a/c/d/index.html", "RelPermalink: /a/c/d/")
|
||||
|
||||
}
|
||||
@@ -144,7 +144,16 @@ func mapToPageMatcherParamsConfig(m map[string]any) (PageMatcherParamsConfig, er
|
||||
// those values will now be moved to the top level.
|
||||
// This should be very unlikely as it would lead to constructs like .Params.params.foo,
|
||||
// and most people see params as an Hugo internal keyword.
|
||||
pcfg.Params = maps.ToStringMap(v)
|
||||
params := maps.ToStringMap(v)
|
||||
if pcfg.Params == nil {
|
||||
pcfg.Params = params
|
||||
} else {
|
||||
for k, v := range params {
|
||||
if _, found := pcfg.Params[k]; !found {
|
||||
pcfg.Params[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case "_target", "target":
|
||||
var target PageMatcher
|
||||
if err := decodePageMatcher(v, &target); err != nil {
|
||||
|
||||
@@ -28,8 +28,7 @@ func TestPageMatcher(t *testing.T) {
|
||||
developmentTestSite := testSite{h: hugo.NewInfo(testConfig{environment: "development"}, nil)}
|
||||
productionTestSite := testSite{h: hugo.NewInfo(testConfig{environment: "production"}, nil)}
|
||||
|
||||
p1, p2, p3 :=
|
||||
&testPage{path: "/p1", kind: "section", lang: "en", site: developmentTestSite},
|
||||
p1, p2, p3 := &testPage{path: "/p1", kind: "section", lang: "en", site: developmentTestSite},
|
||||
&testPage{path: "p2", kind: "page", lang: "no", site: productionTestSite},
|
||||
&testPage{path: "p3", kind: "page", lang: "en"}
|
||||
|
||||
@@ -154,7 +153,6 @@ func TestDecodeCascadeConfig(t *testing.T) {
|
||||
got, err = DecodeCascadeConfig(nil)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(got, qt.IsNotNil)
|
||||
|
||||
}
|
||||
|
||||
type testConfig struct {
|
||||
|
||||
@@ -81,7 +81,6 @@ func TestDecodeRemoteOptions(t *testing.T) {
|
||||
c.Assert(err, isErr)
|
||||
c.Assert(got, qt.DeepEquals, test.want)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +113,6 @@ func TestOptionsNewRequest(t *testing.T) {
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(req.Method, qt.Equals, "GET")
|
||||
c.Assert(req.Header["User-Agent"], qt.DeepEquals, []string{"foo"})
|
||||
|
||||
}
|
||||
|
||||
func TestCalculateResourceID(t *testing.T) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user