diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-03-17 15:51:52 +0100 |
---|---|---|
committer | Steve Francia <steve.francia@gmail.com> | 2016-03-21 21:09:25 -0400 |
commit | de8fc8761aa507ca25fae9163374ec59c5f585ce (patch) | |
tree | 073f77c8c5e403562dcd68fa043b07838086bb54 /hugolib/shortcode.go | |
parent | e5e1bcc271246fa96ea8ffdb6a8bbc879cf296ce (diff) |
Re-render shortcode on template or data file change
Fixes #1971
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r-- | hugolib/shortcode.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index 3c0afd2e7..c0993cc2b 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -263,14 +263,30 @@ func renderShortcode(sc shortcode, parent *ShortcodeWithPage, p *Page, t tpl.Tem func extractAndRenderShortcodes(stringToParse string, p *Page, t tpl.Template) (string, map[string]string, error) { + if p.rendered { + panic("Illegal state: Page already marked as rendered, please reuse the shortcodes") + } + content, shortcodes, err := extractShortcodes(stringToParse, p, t) - renderedShortcodes := make(map[string]string) if err != nil { // try to render what we have whilst logging the error jww.ERROR.Println(err.Error()) } + // Save for reuse + // TODO(bep) refactor this + p.shortcodes = shortcodes + + renderedShortcodes := renderShortcodes(shortcodes, p, t) + + return content, renderedShortcodes, err + +} + +func renderShortcodes(shortcodes map[string]shortcode, p *Page, t tpl.Template) map[string]string { + renderedShortcodes := make(map[string]string) + for key, sc := range shortcodes { if sc.err != nil { // need to have something to replace with @@ -280,8 +296,7 @@ func extractAndRenderShortcodes(stringToParse string, p *Page, t tpl.Template) ( } } - return content, renderedShortcodes, err - + return renderedShortcodes } var shortCodeIllegalState = errors.New("Illegal shortcode state") |