mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-30 02:02:38 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c626d8df8a | |||
| 60d954c785 | |||
| 63e0a92894 | |||
| ce7daa6156 | |||
| 2a0329423c | |||
| 50dc327d1a |
Binary file not shown.
|
Before Width: | Height: | Size: 88 KiB |
@@ -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, "§§§", "```")
|
||||
|
||||
+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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/cache/filecache"
|
||||
"github.com/gohugoio/hugo/common/hugo"
|
||||
"github.com/gohugoio/hugo/common/maps"
|
||||
"github.com/gohugoio/hugo/config/security"
|
||||
|
||||
@@ -63,6 +64,8 @@ type Namespace struct {
|
||||
// If you provide multiple parts for the URL they will be joined together to the final URL.
|
||||
// GetCSV returns nil or a slice slice to use in a short code.
|
||||
func (ns *Namespace) GetCSV(sep string, args ...any) (d [][]string, err error) {
|
||||
hugo.Deprecate("data.GetJSON", "use resources.Get or resources.GetRemote with transform.Unmarshal.", "v0.123.0")
|
||||
|
||||
url, headers := toURLAndHeaders(args)
|
||||
cache := ns.cacheGetCSV
|
||||
|
||||
@@ -102,6 +105,8 @@ func (ns *Namespace) GetCSV(sep string, args ...any) (d [][]string, err error) {
|
||||
// If you provide multiple parts they will be joined together to the final URL.
|
||||
// GetJSON returns nil or parsed JSON to use in a short code.
|
||||
func (ns *Namespace) GetJSON(args ...any) (any, error) {
|
||||
hugo.Deprecate("data.GetJSON", "use resources.Get or resources.GetRemote with transform.Unmarshal.", "v0.123.0")
|
||||
|
||||
var v any
|
||||
url, headers := toURLAndHeaders(args)
|
||||
cache := ns.cacheGetJSON
|
||||
|
||||
Reference in New Issue
Block a user