]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Replace deprecated site.Data with hugo.Data in tests
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 21 Mar 2026 18:09:14 +0000 (19:09 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 21 Mar 2026 18:09:14 +0000 (19:09 +0100)
This also fixes a subtle server reload issue when changing files inside /data and using the recently added hugo.Data method.

hugolib/datafiles_test.go
hugolib/dates_test.go
hugolib/hugo_modules_test.go
hugolib/hugo_sites_build.go
hugolib/hugo_smoke_test.go
hugolib/mount_filters_test.go
hugolib/rebuild_test.go
resources/page/hugoinfo.go

index 4b1b6739f90798e8c2b0902f214a45adbe6ae56d..a5210fd5b1eddd4bda6a2ed88b8ca5de5eb45de3 100644 (file)
@@ -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)
index b140fbcef62acd3f8b5c7c6f4a746bc0dab05e43..29c399a24c555d6769829f6045b6381d460ef221 100644 (file)
@@ -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" }}
 `
 
index 512afb7078ba1f61a428fd7a27c3c73ef89a6849..4ece8463c11e13be6f544258887117eee7f4b083 100644 (file)
@@ -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)
index 98d1d68c74405026ff34c7787017ae28ac1c37c8..0b674207cb9faa8d77000a7abdc60140f90669f6 100644 (file)
@@ -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()
index fb46cff1745ac5ed824df5d117da21a1301bded0..2561b160d538cf055958b3d9d74816eab93b820b 100644 (file)
@@ -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]]
index 3443a43b7caa8818e990090d5c3820064b7040ac..50935a25312033e75c2237b4760277299df7a974 100644 (file)
@@ -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
index d376c162c3a3f2097a4dd6298f50b30f7ca95173..d61e94a5afc108a2d9b362b9b75869d777b79907 100644 (file)
@@ -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 }}|
index 05f4b9f2af99dcf7c29e4ffb55e2810b9a9948ef..831cbd2d322d467390ad0fcdb9ab233fbe7895b3 100644 (file)
@@ -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