summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2018-12-06 10:29:28 +0100
committerBjørn Erik Pedersen <[email protected]>2018-12-06 14:37:25 +0100
commit8378358857d852458d01c667d59d13baa59a719c (patch)
tree2354df95e1d75720cc62bc32329b7154adba3ef8
parent831d23cb4d1ca99cdc15ed31c8ee1f981497be8f (diff)
downloadhugo-8378358857d852458d01c667d59d13baa59a719c.tar.gz
hugo-8378358857d852458d01c667d59d13baa59a719c.zip
hugolib: Add .Site.Sites
Fixes #5504
-rw-r--r--hugolib/hugo_sites.go8
-rw-r--r--hugolib/page.go7
-rw-r--r--hugolib/site.go4
-rw-r--r--hugolib/template_test.go11
4 files changed, 22 insertions, 8 deletions
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 043e049d7..0bb3b4362 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -55,6 +55,14 @@ type HugoSites struct {
gitInfo *gitInfo
}
+func (h *HugoSites) siteInfos() SiteInfos {
+ infos := make(SiteInfos, len(h.Sites))
+ for i, site := range h.Sites {
+ infos[i] = &site.Info
+ }
+ return infos
+}
+
func (h *HugoSites) pickOneAndLogTheRest(errors []error) error {
if len(errors) == 0 {
return nil
diff --git a/hugolib/page.go b/hugolib/page.go
index 4c48a6061..81880023a 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -369,12 +369,7 @@ func (p *Page) Summary() template.HTML {
// Sites is a convenience method to get all the Hugo sites/languages configured.
func (p *Page) Sites() SiteInfos {
- infos := make(SiteInfos, len(p.s.owner.Sites))
- for i, site := range p.s.owner.Sites {
- infos[i] = &site.Info
- }
-
- return infos
+ return p.s.owner.siteInfos()
}
// SearchKeywords implements the related.Document interface needed for fast page searches.
diff --git a/hugolib/site.go b/hugolib/site.go
index d0e6c3018..0579edf6e 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -424,6 +424,10 @@ func (s *SiteInfo) Hugo() hugo.Info {
return s.hugoInfo
}
+// Sites is a convenience method to get all the Hugo sites/languages configured.
+func (s *SiteInfo) Sites() SiteInfos {
+ return s.s.owner.siteInfos()
+}
func (s *SiteInfo) String() string {
return fmt.Sprintf("Site(%q)", s.Title)
}
diff --git a/hugolib/template_test.go b/hugolib/template_test.go
index 32ede5639..56f5dd5ba 100644
--- a/hugolib/template_test.go
+++ b/hugolib/template_test.go
@@ -242,6 +242,7 @@ func TestTemplateFuncs(t *testing.T) {
b := newTestSitesBuilder(t).WithDefaultMultiSiteConfig()
homeTpl := `Site: {{ site.Language.Lang }} / {{ .Site.Language.Lang }} / {{ site.BaseURL }}
+Sites: {{ site.Sites.First.Home.Language.Lang }}
Hugo: {{ hugo.Generator }}
`
@@ -252,8 +253,14 @@ Hugo: {{ hugo.Generator }}
b.CreateSites().Build(BuildCfg{})
- b.AssertFileContent("public/en/index.html", "Site: en / en / http://example.com/blog",
+ b.AssertFileContent("public/en/index.html",
+ "Site: en / en / http://example.com/blog",
+ "Sites: en",
"Hugo: <meta name=\"generator\" content=\"Hugo")
- b.AssertFileContent("public/fr/index.html", "Site: fr / fr / http://example.com/blog")
+ b.AssertFileContent("public/fr/index.html",
+ "Site: fr / fr / http://example.com/blog",
+ "Sites: en",
+ "Hugo: <meta name=\"generator\" content=\"Hugo",
+ )
}