diff options
author | Eli W. Hunter <[email protected]> | 2020-03-14 10:43:10 -0400 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-05-15 21:12:43 +0200 |
commit | 423b8f2fb834139cf31514b14b1c1bf28e43b384 (patch) | |
tree | dcd2d3c2dfcc5e2960056462c2d048906b1acc55 /hugolib/page.go | |
parent | 991934497e88dcd4134a369a213bb5072c51c139 (diff) | |
download | hugo-423b8f2fb834139cf31514b14b1c1bf28e43b384.tar.gz hugo-423b8f2fb834139cf31514b14b1c1bf28e43b384.zip |
Add render template hooks for headings
This commit also
* Renames previous types to be non-specific. (e.g. hookedRenderer rather
than linkRenderer)
Resolves #6713
Diffstat (limited to 'hugolib/page.go')
-rw-r--r-- | hugolib/page.go | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/hugolib/page.go b/hugolib/page.go index fddc25fa0..bd518c1e1 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -375,48 +375,54 @@ func (ps *pageState) initCommonProviders(pp pagePaths) error { return nil } -func (p *pageState) createRenderHooks(f output.Format) (*hooks.Render, error) { - +func (p *pageState) createRenderHooks(f output.Format) (*hooks.Renderers, error) { layoutDescriptor := p.getLayoutDescriptor() layoutDescriptor.RenderingHook = true layoutDescriptor.LayoutOverride = false layoutDescriptor.Layout = "" + var renderers hooks.Renderers + layoutDescriptor.Kind = "render-link" - linkTempl, linkTemplFound, err := p.s.Tmpl().LookupLayout(layoutDescriptor, f) + templ, templFound, err := p.s.Tmpl().LookupLayout(layoutDescriptor, f) if err != nil { return nil, err } + if templFound { + renderers.LinkRenderer = hookRenderer{ + templateHandler: p.s.Tmpl(), + Provider: templ.(tpl.Info), + templ: templ, + } + } layoutDescriptor.Kind = "render-image" - imgTempl, imgTemplFound, err := p.s.Tmpl().LookupLayout(layoutDescriptor, f) + templ, templFound, err = p.s.Tmpl().LookupLayout(layoutDescriptor, f) if err != nil { return nil, err } - - var linkRenderer hooks.LinkRenderer - var imageRenderer hooks.LinkRenderer - - if linkTemplFound { - linkRenderer = contentLinkRenderer{ + if templFound { + renderers.ImageRenderer = hookRenderer{ templateHandler: p.s.Tmpl(), - Provider: linkTempl.(tpl.Info), - templ: linkTempl, + Provider: templ.(tpl.Info), + templ: templ, } } - if imgTemplFound { - imageRenderer = contentLinkRenderer{ + layoutDescriptor.Kind = "render-heading" + templ, templFound, err = p.s.Tmpl().LookupLayout(layoutDescriptor, f) + if err != nil { + return nil, err + } + if templFound { + renderers.HeadingRenderer = hookRenderer{ templateHandler: p.s.Tmpl(), - Provider: imgTempl.(tpl.Info), - templ: imgTempl, + Provider: templ.(tpl.Info), + templ: templ, } } - return &hooks.Render{ - LinkRenderer: linkRenderer, - ImageRenderer: imageRenderer, - }, nil + return &renderers, nil } func (p *pageState) getLayoutDescriptor() output.LayoutDescriptor { |