mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Revert "Consider root and current section's content type if set in front matter"
This reverts commit c790029e1d
.
This commit is contained in:
parent
5dc1f95b63
commit
179de5f5bc
5 changed files with 7 additions and 67 deletions
|
@ -412,26 +412,12 @@ func (p *Page) createLayoutDescriptor() output.LayoutDescriptor {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
var typeCurrentSection string
|
|
||||||
var typeRootSection string
|
|
||||||
curr := p.CurrentSection()
|
|
||||||
// Make sure we use the contentType only. This is the value from front matter.
|
|
||||||
if curr != nil {
|
|
||||||
typeCurrentSection = curr.contentType
|
|
||||||
}
|
|
||||||
first := p.FirstSection()
|
|
||||||
if first != nil {
|
|
||||||
typeRootSection = first.contentType
|
|
||||||
}
|
|
||||||
|
|
||||||
return output.LayoutDescriptor{
|
return output.LayoutDescriptor{
|
||||||
Kind: p.Kind,
|
Kind: p.Kind,
|
||||||
Type: p.Type(),
|
Type: p.Type(),
|
||||||
Lang: p.Lang(),
|
Lang: p.Lang(),
|
||||||
Layout: p.Layout,
|
Layout: p.Layout,
|
||||||
Section: section,
|
Section: section,
|
||||||
TypeCurrentSection: typeCurrentSection,
|
|
||||||
TypeFirstSection: typeRootSection,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,29 +58,6 @@ func (p *Page) CurrentSection() *Page {
|
||||||
return v.parent
|
return v.parent
|
||||||
}
|
}
|
||||||
|
|
||||||
// FirstSection returns the section on level 1 below home, e.g. "/docs".
|
|
||||||
// For the home page, this will return itself.
|
|
||||||
func (p *Page) FirstSection() *Page {
|
|
||||||
v := p
|
|
||||||
if v.origOnCopy != nil {
|
|
||||||
v = v.origOnCopy
|
|
||||||
}
|
|
||||||
|
|
||||||
if v.parent == nil || v.parent.IsHome() {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
parent := v.parent
|
|
||||||
for {
|
|
||||||
current := parent
|
|
||||||
parent = parent.parent
|
|
||||||
if parent == nil || parent.IsHome() {
|
|
||||||
return current
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// InSection returns whether the given page is in the current section.
|
// InSection returns whether the given page is in the current section.
|
||||||
// Note that this will always return false for pages that are
|
// Note that this will always return false for pages that are
|
||||||
// not either regular, home or section pages.
|
// not either regular, home or section pages.
|
||||||
|
|
|
@ -176,8 +176,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||||
active, err := home.InSection(home)
|
active, err := home.InSection(home)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.True(active)
|
assert.True(active)
|
||||||
assert.Equal(p, p.FirstSection())
|
|
||||||
|
|
||||||
}},
|
}},
|
||||||
{"l1", func(p *Page) {
|
{"l1", func(p *Page) {
|
||||||
assert.Equal("L1s", p.title)
|
assert.Equal("L1s", p.title)
|
||||||
|
@ -252,8 +250,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.False(isAncestor)
|
assert.False(isAncestor)
|
||||||
|
|
||||||
assert.Equal(l1, p.FirstSection())
|
|
||||||
|
|
||||||
}},
|
}},
|
||||||
{"perm a,link", func(p *Page) {
|
{"perm a,link", func(p *Page) {
|
||||||
assert.Equal("T9_-1", p.title)
|
assert.Equal("T9_-1", p.title)
|
||||||
|
|
|
@ -35,12 +35,6 @@ type LayoutDescriptor struct {
|
||||||
Kind string
|
Kind string
|
||||||
Lang string
|
Lang string
|
||||||
Layout string
|
Layout string
|
||||||
|
|
||||||
// Any potential type set in the page's current section and the root section
|
|
||||||
// it lives in.
|
|
||||||
TypeFirstSection string
|
|
||||||
TypeCurrentSection string
|
|
||||||
|
|
||||||
// LayoutOverride indicates what we should only look for the above layout.
|
// LayoutOverride indicates what we should only look for the above layout.
|
||||||
LayoutOverride bool
|
LayoutOverride bool
|
||||||
}
|
}
|
||||||
|
@ -133,14 +127,6 @@ func resolvePageTemplate(d LayoutDescriptor, f Format) []string {
|
||||||
b.addTypeVariations(d.Type)
|
b.addTypeVariations(d.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.TypeCurrentSection != "" {
|
|
||||||
b.addTypeVariations(d.TypeCurrentSection)
|
|
||||||
}
|
|
||||||
|
|
||||||
if d.TypeFirstSection != "" {
|
|
||||||
b.addTypeVariations(d.TypeFirstSection)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch d.Kind {
|
switch d.Kind {
|
||||||
case "page":
|
case "page":
|
||||||
b.addLayoutVariations("single")
|
b.addLayoutVariations("single")
|
||||||
|
|
|
@ -90,13 +90,8 @@ func TestLayout(t *testing.T) {
|
||||||
[]string{"_default/mylayout.amp.html", "_default/single.amp.html", "_default/mylayout.html", "_default/single.html"}, 4},
|
[]string{"_default/mylayout.amp.html", "_default/single.amp.html", "_default/mylayout.html", "_default/single.html"}, 4},
|
||||||
{"Page with layout and type", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype"}, "", ampType,
|
{"Page with layout and type", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype"}, "", ampType,
|
||||||
[]string{"myttype/mylayout.amp.html", "myttype/single.amp.html", "myttype/mylayout.html"}, 8},
|
[]string{"myttype/mylayout.amp.html", "myttype/single.amp.html", "myttype/mylayout.html"}, 8},
|
||||||
{"Page with layout and type with subtype", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype/mysubtype", TypeCurrentSection: "cst"}, "", ampType,
|
{"Page with layout and type with subtype", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype/mysubtype"}, "", ampType,
|
||||||
[]string{"myttype/mysubtype/mylayout.amp.html", "myttype/mysubtype/single.amp.html", "myttype/mysubtype/mylayout.html"}, 12},
|
[]string{"myttype/mysubtype/mylayout.amp.html", "myttype/mysubtype/single.amp.html", "myttype/mysubtype/mylayout.html"}, 8},
|
||||||
{"Page with type in section", LayoutDescriptor{Kind: "page", TypeCurrentSection: "cst"}, "", ampType,
|
|
||||||
[]string{"cst/single.amp.html", "cst/single.html", "_default/single.amp.html", "_default/single.html"}, 4},
|
|
||||||
{"Page with type in root section", LayoutDescriptor{Kind: "page", TypeFirstSection: "cst"}, "", ampType,
|
|
||||||
[]string{"cst/single.amp.html", "cst/single.html", "_default/single.amp.html", "_default/single.html"}, 4},
|
|
||||||
|
|
||||||
// RSS
|
// RSS
|
||||||
{"RSS Home", LayoutDescriptor{Kind: "home"}, "", RSSFormat,
|
{"RSS Home", LayoutDescriptor{Kind: "home"}, "", RSSFormat,
|
||||||
[]string{"index.rss.xml", "home.rss.xml", "rss.xml"}, 15},
|
[]string{"index.rss.xml", "home.rss.xml", "rss.xml"}, 15},
|
||||||
|
|
Loading…
Reference in a new issue