Skip to content

Commit

Permalink
Perf
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Dec 6, 2019
1 parent c59d053 commit a8ef747
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
5 changes: 5 additions & 0 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,17 @@ func (ps *pageState) initCommonProviders(pp pagePaths) error {
return nil
}

// TODO1 remove
func (ps *pageState) initOutputFormats() error {

if len(ps.pageOutputs) == 0 {
return nil
}

if true {
return nil
}

c := ps.getContentConverter()
if c == nil || !c.Supports(converter.FeatureRenderHooks) {
return nil
Expand Down
1 change: 1 addition & 0 deletions hugolib/page__new.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func newPageWithContent(f *fileInfo, s *Site, bundled bool, content resource.Ope
}

ps.init.Add(func() (interface{}, error) {
// TODO1
reuseContent := ps.renderable && !ps.shortcodeState.hasShortcodes()

// Creates what's needed for each output format.
Expand Down
27 changes: 27 additions & 0 deletions hugolib/page__output.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package hugolib

import (
"github.com/gohugoio/hugo/markup/converter"
"github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/resource"
Expand Down Expand Up @@ -90,6 +91,32 @@ type pageOutput struct {
cp *pageContentOutput
}

func (o *pageOutput) initRenderHooks() error {
if !o.render || o.cp == nil {
return nil
}

ps := o.cp.p

c := ps.getContentConverter()
if c == nil || !c.Supports(converter.FeatureRenderHooks) {
return nil
}

h, err := ps.createRenderHooks(o.f)
if err != nil {
return err
}
if h == nil {
return nil
}

o.cp.renderHooks = h

return nil

}

func (p *pageOutput) initContentProvider(cp *pageContentOutput) {
if cp == nil {
return
Expand Down
6 changes: 5 additions & 1 deletion hugolib/page__per_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func newPageContentOutput(p *pageState) func(po *pageOutput) (*pageContentOutput
}
}()

if err := po.initRenderHooks(); err != nil {
return err
}

var hasVariants bool

f := po.f
Expand Down Expand Up @@ -245,7 +249,7 @@ type pageContentOutput struct {
// May be nil.
renderHooks *hooks.Render
// Set if there are more than one output format variant
renderHooksHaveVariants bool
renderHooksHaveVariants bool // TODO1 reimplement this in another way

// Content state

Expand Down
20 changes: 20 additions & 0 deletions markup/converter/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ type Render struct {
ImageRenderer LinkRenderer
}

func (r *Render) Eq(other interface{}) bool {
ro, ok := other.(*Render)
if !ok {
return false
}
if r == nil || ro == nil {
return r == nil
}

if r.ImageRenderer.GetIdentity() != ro.ImageRenderer.GetIdentity() {
return false
}

if r.LinkRenderer.GetIdentity() != ro.LinkRenderer.GetIdentity() {
return false
}

return true
}

type LinkRenderer interface {
Render(w io.Writer, ctx LinkContext) error
identity.Provider
Expand Down

0 comments on commit a8ef747

Please sign in to comment.