hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 96f71141bd4b9e0264bce725f6fec0555c46b1c3
parent 487b210fb8a31b3636030ea960f6565b9e6b3c54
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Sat, 12 Nov 2016 17:30:21 +0100

node to page: Export GetPage to the templates

Updates #2297

Diffstat:
Mhugolib/node_as_page_test.go | 2++
Mhugolib/page_collections.go | 4++--
Mhugolib/site.go | 13+++++++++++++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/hugolib/node_as_page_test.go b/hugolib/node_as_page_test.go
@@ -70,6 +70,7 @@ func TestNodesAsPage(t *testing.T) {
 		"# Pages: 9",
 		"Date: 2009-01-02",
 		"Lastmod: 2009-01-03",
+		"GetPage: Section1 ",
 	)
 
 	assertFileContent(t, filepath.Join("public", "sect1", "regular1", "index.html"), false, "Single Title: Page 01", "Content Page 01")
@@ -543,6 +544,7 @@ Menu Item: {{ .Name }}
 {{ end }}
 Date: {{ .Date.Format "2006-01-02" }}
 Lastmod: {{ .Lastmod.Format "2006-01-02" }}
+GetPage: {{ with .Site.GetPage "section" "sect1" }}{{ .Title }}{{ end }} 
 `)
 
 	writeSource(t, filepath.Join("layouts", "_default", "single.html"), `
diff --git a/hugolib/page_collections.go b/hugolib/page_collections.go
@@ -65,8 +65,8 @@ func (c *PageCollections) findPagesByNodeType(n PageType) Pages {
 	return c.findPagesByNodeTypeIn(n, c.Pages)
 }
 
-func (c *PageCollections) getPage(n PageType, path ...string) *Page {
-	pages := c.findPagesByNodeTypeIn(n, c.Pages)
+func (c *PageCollections) getPage(typ PageType, path ...string) *Page {
+	pages := c.findPagesByNodeTypeIn(typ, c.Pages)
 
 	if len(pages) == 0 {
 		return nil
diff --git a/hugolib/site.go b/hugolib/site.go
@@ -1653,6 +1653,19 @@ func (s *Site) Stats() {
 
 }
 
+// GetPage looks up a index page of a given type in the path given.
+// This method may support regular pages in the future, but currently it is a
+// convenient way of getting the home page or
+// a section from a template:
+//    {{ with .Site.GetPage "section" "blog" }}{{ .Title }}{{ end }}
+//
+// This will return nil when no page could be found.
+//
+// The valid page types are: home, section, taxonomy and taxonomyTerm
+func (s *SiteInfo) GetPage(typ PageType, path ...string) *Page {
+	return s.getPage(typ, path...)
+}
+
 func (s *SiteInfo) permalink(plink string) string {
 	return s.permalinkStr(plink)
 }