From: Bjørn Erik Pedersen Date: Sat, 21 Mar 2026 18:09:14 +0000 (+0100) Subject: Replace deprecated site.Data with hugo.Data in tests X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=a8fca598e6c33aea1257970e791bbf80891b89c0;p=brevno-suite%2Fhugo Replace deprecated site.Data with hugo.Data in tests This also fixes a subtle server reload issue when changing files inside /data and using the recently added hugo.Data method. --- diff --git a/hugolib/datafiles_test.go b/hugolib/datafiles_test.go index 4b1b6739f..a5210fd5b 100644 --- a/hugolib/datafiles_test.go +++ b/hugolib/datafiles_test.go @@ -37,10 +37,10 @@ v1 = "a_v1_theme" -- themes/mytheme/data/d.toml -- v1 = "d_v1_theme" -- layouts/home.html -- -a: {{ site.Data.a.v1 }}| -b: {{ site.Data.b.v1 }}| -cd: {{ site.Data.c.d.v1 }}| -d: {{ site.Data.d.v1 }}| +a: {{ hugo.Data.a.v1 }}| +b: {{ hugo.Data.b.v1 }}| +cd: {{ hugo.Data.c.d.v1 }}| +d: {{ hugo.Data.d.v1 }}| ` b := Test(t, files) @@ -57,8 +57,8 @@ baseURL = "https://example.com" -- data/MyFolder/MyData.toml -- v1 = "my_v1" -- layouts/home.html -- -{{ site.Data }} -v1: {{ site.Data.MyFolder.MyData.v1 }}| +{{ hugo.Data }} +v1: {{ hugo.Data.MyFolder.MyData.v1 }}| ` b := Test(t, files) @@ -75,7 +75,7 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term'] -- assets/data/foo.toml -- content = "I am assets/data/foo.toml" -- layouts/home.html -- -|{{ site.Data.foo.content }}| +|{{ hugo.Data.foo.content }}| ` b := Test(t, files) diff --git a/hugolib/dates_test.go b/hugolib/dates_test.go index b140fbcef..29c399a24 100644 --- a/hugolib/dates_test.go +++ b/hugolib/dates_test.go @@ -229,8 +229,8 @@ talks = [ { date = 2050-02-13, name = "Future talk 2" }, ] -- layouts/home.html -- -{{ $futureTalks := where site.Data.mydata.talks "date" ">" now }} -{{ $pastTalks := where site.Data.mydata.talks "date" "<" now }} +{{ $futureTalks := where hugo.Data.mydata.talks "date" ">" now }} +{{ $pastTalks := where hugo.Data.mydata.talks "date" "<" now }} {{ $homeDate := site.Home.Date }} {{ $p1Date := (site.GetPage "p1").Date }} @@ -239,9 +239,9 @@ Past talks: {{ len $pastTalks }} Home's Date should be greater than past: {{ gt $homeDate (index $pastTalks 0).date }} Home's Date should be less than future: {{ lt $homeDate (index $futureTalks 0).date }} -Home's Date should be equal mydata date: {{ eq $homeDate site.Data.mydata.date }} +Home's Date should be equal mydata date: {{ eq $homeDate hugo.Data.mydata.date }} Home date: {{ $homeDate }} -mydata.date: {{ site.Data.mydata.date }} +mydata.date: {{ hugo.Data.mydata.date }} Full time: {{ $p1Date | time.Format ":time_full" }} ` diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go index 512afb707..4ece8463c 100644 --- a/hugolib/hugo_modules_test.go +++ b/hugolib/hugo_modules_test.go @@ -358,7 +358,7 @@ target = "data/extra" -- extra-data/test.yaml -- message: Hugo Rocks -- layouts/home.html -- -{{ site.Data.extra.test.message }} +{{ hugo.Data.extra.test.message }} ` b := Test(t, files) diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go index 98d1d68c7..0b674207c 100644 --- a/hugolib/hugo_sites_build.go +++ b/hugolib/hugo_sites_build.go @@ -1055,7 +1055,7 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo case files.ComponentFolderData: logger.Println("Data changed", pathInfo.Path()) - // This should cover all usage of site.Data. + // This should cover all usage of hugo.Data. // Currently very coarse grained. changes = append(changes, siteidentities.Data) h.init.data.Reset() diff --git a/hugolib/hugo_smoke_test.go b/hugolib/hugo_smoke_test.go index fb46cff17..2561b160d 100644 --- a/hugolib/hugo_smoke_test.go +++ b/hugolib/hugo_smoke_test.go @@ -633,8 +633,8 @@ path = "mytheme" -- layouts/home.html -- i18n s1: {{ i18n "s1" }}| i18n s2: {{ i18n "s2" }}| -data s1: {{ site.Data.d1.s1 }}| -data s2: {{ site.Data.d1.s2 }}| +data s1: {{ hugo.Data.d1.s1 }}| +data s2: {{ hugo.Data.d1.s2 }}| title: {{ .Title }}| -- themes/mytheme/hugo.toml -- [[module.mounts]] diff --git a/hugolib/mount_filters_test.go b/hugolib/mount_filters_test.go index 3443a43b7..50935a253 100644 --- a/hugolib/mount_filters_test.go +++ b/hugolib/mount_filters_test.go @@ -72,7 +72,7 @@ foo -- assets/js/include.js -- foo -- layouts/home.html -- -Data: {{ site.Data }}:END +Data: {{ hugo.Data }}:END Template: {{ templates.Exists "partials/foo.html" }}:END Resource1: {{ resources.Get "js/include.js" }}:END diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go index d376c162c..d61e94a5a 100644 --- a/hugolib/rebuild_test.go +++ b/hugolib/rebuild_test.go @@ -1394,10 +1394,10 @@ title: "Home" title: "P1" --- -Foo inline: {{< foo.inline >}}{{ site.Data.mydata.foo }}|{{< /foo.inline >}} +Foo inline: {{< foo.inline >}}{{ hugo.Data.mydata.foo }}|{{< /foo.inline >}} -- layouts/_shortcodes/data.html -- {{ $path := split (.Get 0) "." }} -{{ $data := index site.Data $path }} +{{ $data := index hugo.Data $path }} Foo: {{ $data }}| -- layouts/home.html -- Content: {{ .Content }}| diff --git a/resources/page/hugoinfo.go b/resources/page/hugoinfo.go index 05f4b9f2a..831cbd2d3 100644 --- a/resources/page/hugoinfo.go +++ b/resources/page/hugoinfo.go @@ -20,6 +20,8 @@ import ( "github.com/gohugoio/hugo/common/hstore" "github.com/gohugoio/hugo/common/hugo" "github.com/gohugoio/hugo/common/version" + "github.com/gohugoio/hugo/identity" + "github.com/gohugoio/hugo/resources/page/siteidentities" ) var _ hstore.StoreProvider = (*HugoInfo)(nil) @@ -114,6 +116,15 @@ func (i HugoInfo) IsMultilingual() bool { return i.opts.Conf.IsMultilingual() } +// For internal use. +func (s HugoInfo) ForEeachIdentityByName(name string, f func(identity.Identity) bool) { + if id, found := siteidentities.FromString(name); found { + if f(id) { + return + } + } +} + // HugoInfoConfigProvider represents the config options that are relevant for HugoInfo. type HugoInfoConfigProvider interface { Environment() string