hugo

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

git clone git://git.shimmy1996.com/hugo.git
commit c7c6b47ba8bb098cf9fac778f7818afba40a1e2f
parent 08fa2b112407c1fe180e6c02dd8fe63735608336
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Sun, 19 Mar 2017 15:25:32 +0100

hubolib: Pick layout per output format

Diffstat:
Mhugolib/alias.go | 4++--
Mhugolib/page.go | 28+---------------------------
Mhugolib/page_output.go | 28++++++++++++++++++++++++++++
Mhugolib/page_test.go | 11-----------
Mhugolib/site_render.go | 3++-
5 files changed, 33 insertions(+), 41 deletions(-)
diff --git a/hugolib/alias.go b/hugolib/alias.go
@@ -3,7 +3,7 @@
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
-// http://wwa.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
@@ -29,7 +29,7 @@ import (
 
 const (
 	alias      = "<!DOCTYPE html><html><head><title>{{ .Permalink }}</title><link rel=\"canonical\" href=\"{{ .Permalink }}\"/><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"refresh\" content=\"0; url={{ .Permalink }}\" /></head></html>"
-	aliasXHtml = "<!DOCTYPE html><html xmlns=\"http://wwa.w3.org/1999/xhtml\"><head><title>{{ .Permalink }}</title><link rel=\"canonical\" href=\"{{ .Permalink }}\"/><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"refresh\" content=\"0; url={{ .Permalink }}\" /></head></html>"
+	aliasXHtml = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>{{ .Permalink }}</title><link rel=\"canonical\" href=\"{{ .Permalink }}\"/><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"refresh\" content=\"0; url={{ .Permalink }}\" /></head></html>"
 )
 
 var defaultAliasTemplates *template.Template
diff --git a/hugolib/page.go b/hugolib/page.go
@@ -656,23 +656,6 @@ func (p *Page) Section() string {
 	return p.Source.Section()
 }
 
-func (p *Page) layouts(layouts ...string) []string {
-	// TODO(bep) output the logic here needs to be redone.
-	if len(layouts) == 0 && len(p.layoutsCalculated) > 0 {
-		return p.layoutsCalculated
-	}
-
-	layoutOverride := ""
-	if len(layouts) > 0 {
-		layoutOverride = layouts[0]
-	}
-
-	return p.s.layoutHandler.For(
-		p.layoutDescriptor,
-		layoutOverride,
-		output.HTMLType)
-}
-
 // TODO(bep) consolidate and test these KindHome switches (see other layouts methods)s
 // rssLayouts returns RSS layouts to use for the RSS version of this page, nil
 // if no RSS should be rendered.
@@ -1285,11 +1268,6 @@ func (p *Page) Menus() PageMenus {
 	return p.pageMenus
 }
 
-func (p *Page) Render(layout ...string) template.HTML {
-	l := p.layouts(layout...)
-	return p.s.Tmpl.ExecuteTemplateToHTML(p, l...)
-}
-
 func (p *Page) determineMarkupType() string {
 	// Try markup explicitly set in the frontmatter
 	p.Markup = helpers.GuessType(p.Markup)
@@ -1420,7 +1398,6 @@ func (p *Page) FullFilePath() string {
 func (p *Page) prepareLayouts() error {
 	// TODO(bep): Check the IsRenderable logic.
 	if p.Kind == KindPage {
-		var layouts []string
 		if !p.IsRenderable() {
 			// TODO(bep) output
 			self := "__" + p.UniqueID()
@@ -1428,11 +1405,8 @@ func (p *Page) prepareLayouts() error {
 			if err != nil {
 				return err
 			}
-			layouts = append(layouts, self)
-		} else {
-			layouts = append(layouts, p.layouts()...)
+			p.layoutsCalculated = []string{self}
 		}
-		p.layoutsCalculated = layouts
 	}
 	return nil
 }
diff --git a/hugolib/page_output.go b/hugolib/page_output.go
@@ -14,6 +14,7 @@
 package hugolib
 
 import (
+	"html/template"
 	"sync"
 
 	"github.com/spf13/hugo/output"
@@ -81,3 +82,30 @@ func (p *PageOutput) copy() *PageOutput {
 	}
 	return c
 }
+
+func (p *PageOutput) layouts(layouts ...string) []string {
+	// TODO(bep) output the logic here needs to be redone.
+	if len(layouts) == 0 && len(p.layoutsCalculated) > 0 {
+		return p.layoutsCalculated
+	}
+
+	layoutOverride := ""
+	if len(layouts) > 0 {
+		layoutOverride = layouts[0]
+	}
+
+	return p.s.layoutHandler.For(
+		p.layoutDescriptor,
+		layoutOverride,
+		p.outputFormat)
+}
+
+func (p *PageOutput) Render(layout ...string) template.HTML {
+	l := p.layouts(layout...)
+	return p.s.Tmpl.ExecuteTemplateToHTML(p, l...)
+}
+
+// TODO(bep) output
+func (p *Page) Render(layout ...string) template.HTML {
+	return p.mainPageOutput.Render(layout...)
+}
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
@@ -547,12 +547,6 @@ func checkPageType(t *testing.T, page *Page, pageType string) {
 	}
 }
 
-func checkPageLayout(t *testing.T, page *Page, layout ...string) {
-	if !listEqual(page.layouts(), layout) {
-		t.Fatalf("Page layout is:\n%s.  Expected:\n%s", page.layouts(), layout)
-	}
-}
-
 func checkPageDate(t *testing.T, page *Page, time time.Time) {
 	if page.Date != time {
 		t.Fatalf("Page date is: %s.  Expected: %s", page.Date, time)
@@ -659,11 +653,6 @@ func TestCreateNewPage(t *testing.T) {
 		checkPageContent(t, p, normalizeExpected(ext, "<p>Simple Page</p>\n"))
 		checkPageSummary(t, p, "Simple Page")
 		checkPageType(t, p, "page")
-		checkPageLayout(t, p,
-			"page/single.html.html", "page/single.html",
-			"_default/single.html.html", "_default/single.html",
-			"theme/page/single.html.html", "theme/page/single.html",
-			"theme/_default/single.html.html", "theme/_default/single.html")
 		checkTruncation(t, p, false, "simple short page")
 	}
 
diff --git a/hugolib/site_render.go b/hugolib/site_render.go
@@ -147,10 +147,11 @@ func (s *Site) renderPaginator(p *PageOutput) error {
 			pageNumber := i + 1
 			addend := fmt.Sprintf("/%s/%d", paginatePath, pageNumber)
 			targetPath, _ := p.targetPath(addend)
+			layouts := p.layouts()
 
 			if err := s.renderAndWritePage(
 				pagerNode.Title,
-				targetPath, pagerNode, p.layouts()...); err != nil {
+				targetPath, pagerNode, layouts...); err != nil {
 				return err
 			}