aboutsummaryrefslogtreecommitdiffhomepage
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-11-27 13:42:36 +0100
committerBjørn Erik Pedersen <[email protected]>2019-12-18 11:44:40 +0100
commite625088ef5a970388ad50e464e87db56b358dac4 (patch)
treef7b26dec1f3695411558d05ca7d0995817a42250 /output
parent67f3aa72cf9aaf3d6e447fa6bc12de704d46adf7 (diff)
downloadhugo-e625088ef5a970388ad50e464e87db56b358dac4.tar.gz
hugo-e625088ef5a970388ad50e464e87db56b358dac4.zip
Add render template hooks for links and images
This commit also * revises the change detection for templates used by content files in server mode. * Adds a Page.RenderString method Fixes #6545 Fixes #4663 Closes #6043
Diffstat (limited to 'output')
-rw-r--r--output/layout.go34
-rw-r--r--output/layout_test.go3
2 files changed, 27 insertions, 10 deletions
diff --git a/output/layout.go b/output/layout.go
index 055d742b1..091684bee 100644
--- a/output/layout.go
+++ b/output/layout.go
@@ -37,6 +37,12 @@ type LayoutDescriptor struct {
Layout string
// LayoutOverride indicates what we should only look for the above layout.
LayoutOverride bool
+
+ RenderingHook bool
+}
+
+func (d LayoutDescriptor) isList() bool {
+ return !d.RenderingHook && d.Kind != "page"
}
// LayoutHandler calculates the layout template to use to render a given output type.
@@ -89,7 +95,7 @@ type layoutBuilder struct {
func (l *layoutBuilder) addLayoutVariations(vars ...string) {
for _, layoutVar := range vars {
- if l.d.LayoutOverride && layoutVar != l.d.Layout {
+ if !l.d.RenderingHook && l.d.LayoutOverride && layoutVar != l.d.Layout {
continue
}
l.layoutVariations = append(l.layoutVariations, layoutVar)
@@ -99,6 +105,9 @@ func (l *layoutBuilder) addLayoutVariations(vars ...string) {
func (l *layoutBuilder) addTypeVariations(vars ...string) {
for _, typeVar := range vars {
if !reservedSections[typeVar] {
+ if l.d.RenderingHook {
+ typeVar = typeVar + renderingHookRoot
+ }
l.typeVariations = append(l.typeVariations, typeVar)
}
}
@@ -115,16 +124,21 @@ func (l *layoutBuilder) addKind() {
l.addTypeVariations(l.d.Kind)
}
+const renderingHookRoot = "/_markup"
+
func resolvePageTemplate(d LayoutDescriptor, f Format) []string {
b := &layoutBuilder{d: d, f: f}
- if d.Layout != "" {
- b.addLayoutVariations(d.Layout)
- }
-
- if d.Type != "" {
- b.addTypeVariations(d.Type)
+ if d.RenderingHook {
+ b.addLayoutVariations(d.Kind)
+ } else {
+ if d.Layout != "" {
+ b.addLayoutVariations(d.Layout)
+ }
+ if d.Type != "" {
+ b.addTypeVariations(d.Type)
+ }
}
switch d.Kind {
@@ -159,7 +173,7 @@ func resolvePageTemplate(d LayoutDescriptor, f Format) []string {
}
isRSS := f.Name == RSSFormat.Name
- if isRSS {
+ if !d.RenderingHook && isRSS {
// The historic and common rss.xml case
b.addLayoutVariations("")
}
@@ -167,14 +181,14 @@ func resolvePageTemplate(d LayoutDescriptor, f Format) []string {
// All have _default in their lookup path
b.addTypeVariations("_default")
- if d.Kind != "page" {
+ if d.isList() {
// Add the common list type
b.addLayoutVariations("list")
}
layouts := b.resolveVariations()
- if isRSS {
+ if !d.RenderingHook && isRSS {
layouts = append(layouts, "_internal/_default/rss.xml")
}
diff --git a/output/layout_test.go b/output/layout_test.go
index c6267b274..cff275929 100644
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -111,6 +111,9 @@ func TestLayout(t *testing.T) {
[]string{"section/shortcodes.amp.html"}, 12},
{"Reserved section, partials", LayoutDescriptor{Kind: "section", Section: "partials", Type: "partials"}, "", ampType,
[]string{"section/partials.amp.html"}, 12},
+ // We may add type support ... later.
+ {"Content hook", LayoutDescriptor{Kind: "render-link", RenderingHook: true, Layout: "mylayout", Section: "blog"}, "", ampType,
+ []string{"_default/_markup/render-link.amp.html", "_default/_markup/render-link.html"}, 2},
} {
c.Run(this.name, func(c *qt.C) {
l := NewLayoutHandler()