mirror of
https://github.com/gohugoio/hugo.git
synced 2025-01-30 19:13:52 +00:00
hubolib: Pick layout per output format
This commit is contained in:
parent
08fa2b1124
commit
c7c6b47ba8
5 changed files with 33 additions and 41 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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...)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue