summaryrefslogtreecommitdiffstats
path: root/tpl/tplimpl/template.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-01-30 11:43:20 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-01-30 20:12:19 +0100
commit5b7cb258ec26d7de690099f5dc39935b8d728155 (patch)
tree53544c8ab46e3fffda4a1e33c5d6e705183e2652 /tpl/tplimpl/template.go
parent80595bbe3e7901ecd6200e59d43af142c3c85b6b (diff)
Create default link and image render hooks
Fixes #11933
Diffstat (limited to 'tpl/tplimpl/template.go')
-rw-r--r--tpl/tplimpl/template.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go
index a8ba6815d..63dc29662 100644
--- a/tpl/tplimpl/template.go
+++ b/tpl/tplimpl/template.go
@@ -55,6 +55,7 @@ const (
shortcodesPathPrefix = "shortcodes/"
internalPathPrefix = "_internal/"
+ embeddedPathPrefix = "_embedded/"
baseFileBase = "baseof"
)
@@ -517,11 +518,19 @@ func (t *templateHandler) findLayout(d layouts.LayoutDescriptor, f output.Format
func (t *templateHandler) newTemplateInfo(name, tpl string) templateInfo {
var isText bool
+ var isEmbedded bool
+
+ if strings.HasPrefix(name, embeddedPathPrefix) {
+ isEmbedded = true
+ name = strings.TrimPrefix(name, embeddedPathPrefix)
+ }
+
name, isText = t.nameIsText(name)
return templateInfo{
- name: name,
- isText: isText,
- template: tpl,
+ name: name,
+ isText: isText,
+ isEmbedded: isEmbedded,
+ template: tpl,
}
}
@@ -772,7 +781,7 @@ func (t *templateHandler) loadEmbedded() error {
}
if _, found := t.Lookup(templateName); !found {
- if err := t.AddTemplate(templateName, templ); err != nil {
+ if err := t.AddTemplate(embeddedPathPrefix+templateName, templ); err != nil {
return err
}
}
@@ -781,7 +790,7 @@ func (t *templateHandler) loadEmbedded() error {
// TODO(bep) avoid reparsing these aliases
for _, alias := range aliases {
alias = internalPathPrefix + alias
- if err := t.AddTemplate(alias, templ); err != nil {
+ if err := t.AddTemplate(embeddedPathPrefix+alias, templ); err != nil {
return err
}
}
@@ -1026,6 +1035,8 @@ func (t *templateNamespace) parse(info templateInfo) (*templateState, error) {
return ts, nil
}
+var _ tpl.IsInternalTemplateProvider = (*templateState)(nil)
+
type templateState struct {
tpl.Template
@@ -1037,6 +1048,10 @@ type templateState struct {
baseInfo templateInfo // Set when a base template is used.
}
+func (t *templateState) IsInternalTemplate() bool {
+ return t.info.isEmbedded
+}
+
func (t *templateState) GetIdentity() identity.Identity {
return t.id
}