This also fixes a subtle server reload issue when changing files inside /data and using the recently added hugo.Data method.
-- 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)
-- 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)
-- 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)
{ 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 }}
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" }}
`
-- extra-data/test.yaml --
message: Hugo Rocks
-- layouts/home.html --
-{{ site.Data.extra.test.message }}
+{{ hugo.Data.extra.test.message }}
`
b := Test(t, files)
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()
-- 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]]
-- 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
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 }}|
"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)
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