mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
028b356787
commit
42e150fbfa
6 changed files with 83 additions and 13 deletions
|
@ -981,14 +981,17 @@ func (h *HugoSites) resetPageStateFromEvents(idset identity.Identities) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range p.shortcodeState.shortcodes {
|
for _, s := range p.shortcodeState.shortcodes {
|
||||||
for id := range idset {
|
for _, templ := range s.templs {
|
||||||
if idm, ok := s.info.(identity.Manager); ok && idm.Search(id) != nil {
|
sid := templ.(identity.Manager)
|
||||||
for _, po := range p.pageOutputs {
|
for id := range idset {
|
||||||
if po.cp != nil {
|
if sid.Search(id) != nil {
|
||||||
po.cp.Reset()
|
for _, po := range p.pageOutputs {
|
||||||
|
if po.cp != nil {
|
||||||
|
po.cp.Reset()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ baseURL = "https://example.com"
|
||||||
title = "Rebuild this"
|
title = "Rebuild this"
|
||||||
contentDir = "content"
|
contentDir = "content"
|
||||||
enableInlineShortcodes = true
|
enableInlineShortcodes = true
|
||||||
|
timeout = "5s"
|
||||||
|
|
||||||
|
|
||||||
`
|
`
|
||||||
|
@ -213,6 +214,46 @@ prender: {{ $p.Title }}|{{ $p.Content }}
|
||||||
|
|
||||||
b.AssertFileContent("public/index.html", `
|
b.AssertFileContent("public/index.html", `
|
||||||
Render /prender/: Baseof:Single Main: Page 1|Mypartial1: Mypartial1|Mypartial3: Mypartial3 Edited:END
|
Render /prender/: Baseof:Single Main: Page 1|Mypartial1: Mypartial1|Mypartial3: Mypartial3 Edited:END
|
||||||
|
`)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Edit RSS shortcode", func(t *testing.T) {
|
||||||
|
b := createSiteBuilder(t)
|
||||||
|
|
||||||
|
b.WithContent("output.md", `---
|
||||||
|
title: Output
|
||||||
|
outputs: ["HTML", "AMP"]
|
||||||
|
layout: output
|
||||||
|
---
|
||||||
|
|
||||||
|
Content for Output.
|
||||||
|
|
||||||
|
{{< output >}}
|
||||||
|
|
||||||
|
`)
|
||||||
|
|
||||||
|
b.WithTemplates(
|
||||||
|
"layouts/_default/output.html", `Output HTML: {{ .RelPermalink }}|{{ .Content }}`,
|
||||||
|
"layouts/_default/output.amp.html", `Output AMP: {{ .RelPermalink }}|{{ .Content }}`,
|
||||||
|
"layouts/shortcodes/output.html", `Output Shortcode HTML`,
|
||||||
|
"layouts/shortcodes/output.amp.html", `Output Shortcode AMP`)
|
||||||
|
|
||||||
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
|
b.AssertFileContent("public/output/index.html", `
|
||||||
|
Output Shortcode HTML
|
||||||
|
`)
|
||||||
|
b.AssertFileContent("public/amp/output/index.html", `
|
||||||
|
Output Shortcode AMP
|
||||||
|
`)
|
||||||
|
|
||||||
|
b.EditFiles("layouts/shortcodes/output.amp.html", `Output Shortcode AMP Edited`)
|
||||||
|
|
||||||
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
|
b.AssertFileContent("public/amp/output/index.html", `
|
||||||
|
Output Shortcode AMP Edited
|
||||||
`)
|
`)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -176,7 +176,8 @@ type shortcode struct {
|
||||||
ordinal int
|
ordinal int
|
||||||
err error
|
err error
|
||||||
|
|
||||||
info tpl.Info
|
info tpl.Info // One of the output formats (arbitrary)
|
||||||
|
templs []tpl.Template // All output formats
|
||||||
|
|
||||||
// If set, the rendered shortcode is sent as part of the surrounding content
|
// If set, the rendered shortcode is sent as part of the surrounding content
|
||||||
// to Blackfriday and similar.
|
// to Blackfriday and similar.
|
||||||
|
@ -541,15 +542,14 @@ Loop:
|
||||||
|
|
||||||
sc.name = currItem.ValStr()
|
sc.name = currItem.ValStr()
|
||||||
|
|
||||||
// Check if the template expects inner content.
|
// Used to check if the template expects inner content.
|
||||||
// We pick the first template for an arbitrary output format
|
templs := s.s.Tmpl().LookupVariants(sc.name)
|
||||||
// if more than one. It is "all inner or no inner".
|
if templs == nil {
|
||||||
tmpl, found, _ := s.s.Tmpl().LookupVariant(sc.name, tpl.TemplateVariants{})
|
|
||||||
if !found {
|
|
||||||
return nil, _errors.Errorf("template for shortcode %q not found", sc.name)
|
return nil, _errors.Errorf("template for shortcode %q not found", sc.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.info = tmpl.(tpl.Info)
|
sc.info = templs[0].(tpl.Info)
|
||||||
|
sc.templs = templs
|
||||||
case currItem.IsInlineShortcodeName():
|
case currItem.IsInlineShortcodeName():
|
||||||
sc.name = currItem.ValStr()
|
sc.name = currItem.ValStr()
|
||||||
sc.isInline = true
|
sc.isInline = true
|
||||||
|
|
|
@ -40,6 +40,10 @@ func (templateFinder) LookupVariant(name string, variants tpl.TemplateVariants)
|
||||||
return nil, false, false
|
return nil, false, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (templateFinder) LookupVariants(name string) []tpl.Template {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (templateFinder) LookupLayout(d output.LayoutDescriptor, f output.Format) (tpl.Template, bool, error) {
|
func (templateFinder) LookupLayout(d output.LayoutDescriptor, f output.Format) (tpl.Template, bool, error) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ type TemplateLookupVariant interface {
|
||||||
// We are currently only interested in output formats, so we should improve
|
// We are currently only interested in output formats, so we should improve
|
||||||
// this for speed.
|
// this for speed.
|
||||||
LookupVariant(name string, variants TemplateVariants) (Template, bool, bool)
|
LookupVariant(name string, variants TemplateVariants) (Template, bool, bool)
|
||||||
|
LookupVariants(name string) []Template
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template is the common interface between text/template and html/template.
|
// Template is the common interface between text/template and html/template.
|
||||||
|
|
|
@ -354,6 +354,23 @@ func (t *templateHandler) LookupVariant(name string, variants tpl.TemplateVarian
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LookupVariants returns all variants of name, nil if none found.
|
||||||
|
func (t *templateHandler) LookupVariants(name string) []tpl.Template {
|
||||||
|
name = templateBaseName(templateShortcode, name)
|
||||||
|
s, found := t.shortcodes[name]
|
||||||
|
if !found {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
variants := make([]tpl.Template, len(s.variants))
|
||||||
|
for i := 0; i < len(variants); i++ {
|
||||||
|
variants[i] = s.variants[i].ts
|
||||||
|
}
|
||||||
|
|
||||||
|
return variants
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (t *templateHandler) HasTemplate(name string) bool {
|
func (t *templateHandler) HasTemplate(name string) bool {
|
||||||
|
|
||||||
if _, found := t.baseof[name]; found {
|
if _, found := t.baseof[name]; found {
|
||||||
|
@ -966,6 +983,10 @@ func (t *textTemplateWrapperWithLock) LookupVariant(name string, variants tpl.Te
|
||||||
panic("not supported")
|
panic("not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *textTemplateWrapperWithLock) LookupVariants(name string) []tpl.Template {
|
||||||
|
panic("not supported")
|
||||||
|
}
|
||||||
|
|
||||||
func (t *textTemplateWrapperWithLock) Parse(name, tpl string) (tpl.Template, error) {
|
func (t *textTemplateWrapperWithLock) Parse(name, tpl string) (tpl.Template, error) {
|
||||||
t.Lock()
|
t.Lock()
|
||||||
defer t.Unlock()
|
defer t.Unlock()
|
||||||
|
|
Loading…
Reference in a new issue