diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-04-15 15:17:46 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-04-15 18:31:56 +0200 |
commit | 56550d1e449f45ebee398ac8a9e3b9818b3ee60e (patch) | |
tree | 4f1e262784a3b875b7a5ed4644afd85fcc0a7282 /tpl/tplimpl/template.go | |
parent | 7881b0965f8b83d03379e9ed102cd0c3bce297e2 (diff) |
hugolib: Fix shortcode namespace issue
Fixes #5863
Diffstat (limited to 'tpl/tplimpl/template.go')
-rw-r--r-- | tpl/tplimpl/template.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go index 49b9e1c34..8fcaa8d64 100644 --- a/tpl/tplimpl/template.go +++ b/tpl/tplimpl/template.go @@ -16,7 +16,6 @@ package tplimpl import ( "fmt" "html/template" - "path" "strings" texttemplate "text/template" @@ -112,8 +111,27 @@ type templateHandler struct { *deps.Deps } +const ( + shortcodesPathPrefix = "shortcodes/" + internalPathPrefix = "_internal/" +) + +// resolves _internal/shortcodes/param.html => param.html etc. +func templateBaseName(typ templateType, name string) string { + name = strings.TrimPrefix(name, internalPathPrefix) + switch typ { + case templateShortcode: + return strings.TrimPrefix(name, shortcodesPathPrefix) + default: + panic("not implemented") + } + +} + func (t *templateHandler) addShortcodeVariant(name string, info tpl.Info, templ tpl.Template) { - shortcodename, variants := templateNameAndVariants(path.Base(name)) + base := templateBaseName(templateShortcode, name) + + shortcodename, variants := templateNameAndVariants(base) templs, found := t.shortcodes[shortcodename] if !found { @@ -204,7 +222,7 @@ func (t *templateHandler) applyTemplateInfo(templ tpl.Template, found bool) (tpl // This currently only applies to shortcodes and what we get here is the // shortcode name. func (t *templateHandler) LookupVariant(name string, variants tpl.TemplateVariants) (tpl.Template, bool, bool) { - name = path.Base(name) + name = templateBaseName(templateShortcode, name) s, found := t.shortcodes[name] if !found { return nil, false, false |