Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-06-30 14:03:26 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-06-30 14:10:04 +0300
commitc790029e1dbb0b66af18d05764bd6045deb2e180 (patch)
tree6273e53cc6f6910b6a43d317178dcafc8506d3fb /output/layout.go
parent554553c09c7657d28681e1fa0638806a452737a0 (diff)
Consider root and current section's content type if set in front matter
This should allow for less duplication of templates. Before this commit it was possible to override the content page of a given page/section, but only one page at a time. Full "template sets" can now be inherited by setting `type: blog` etc. in the section content page's front matter, and that type will be considered when looking for layouts for all pages in that section. For nested sections, it will use consider both `type` set in the current section first, then `type` set in the first section below home, e.g. `/docs`. This commit also adds a new Page method: `FirstSection`. This navigates up to the first section below home (e.g. `/docs`). For the home page it will return itself. Fixes #4891
Diffstat (limited to 'output/layout.go')
-rw-r--r--output/layout.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/output/layout.go b/output/layout.go
index f83490d81..2483093b0 100644
--- a/output/layout.go
+++ b/output/layout.go
@@ -35,6 +35,12 @@ type LayoutDescriptor struct {
Kind string
Lang 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 bool
}
@@ -127,6 +133,14 @@ func resolvePageTemplate(d LayoutDescriptor, f Format) []string {
b.addTypeVariations(d.Type)
}
+ if d.TypeCurrentSection != "" {
+ b.addTypeVariations(d.TypeCurrentSection)
+ }
+
+ if d.TypeFirstSection != "" {
+ b.addTypeVariations(d.TypeFirstSection)
+ }
+
switch d.Kind {
case "page":
b.addLayoutVariations("single")