mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Create lightweight forks of text/template and html/template
This commit also removes support for Ace and Amber templates. Updates #6594
This commit is contained in:
@@ -15,17 +15,18 @@ package tplimpl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
|
||||
"strings"
|
||||
texttemplate "text/template"
|
||||
"text/template/parse"
|
||||
|
||||
template "github.com/gohugoio/hugo/tpl/internal/go_templates/htmltemplate"
|
||||
|
||||
texttemplate "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate"
|
||||
"github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
"github.com/gohugoio/hugo/tpl/tplimpl/embedded"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/eknkc/amber"
|
||||
|
||||
"os"
|
||||
|
||||
"github.com/gohugoio/hugo/output"
|
||||
@@ -56,9 +57,6 @@ var (
|
||||
_ templateFuncsterTemplater = (*textTemplates)(nil)
|
||||
)
|
||||
|
||||
// Protecting global map access (Amber)
|
||||
var amberMu sync.Mutex
|
||||
|
||||
type templateErr struct {
|
||||
name string
|
||||
err error
|
||||
@@ -98,8 +96,6 @@ type templateHandler struct {
|
||||
text *textTemplates
|
||||
html *htmlTemplates
|
||||
|
||||
amberFuncMap template.FuncMap
|
||||
|
||||
errors []*templateErr
|
||||
|
||||
// This is the filesystem to load the templates from. All the templates are
|
||||
@@ -778,23 +774,6 @@ func (t *templateHandler) initFuncs() {
|
||||
}
|
||||
}
|
||||
|
||||
// Amber is HTML only.
|
||||
t.amberFuncMap = template.FuncMap{}
|
||||
|
||||
amberMu.Lock()
|
||||
for k, v := range amber.FuncMap {
|
||||
t.amberFuncMap[k] = v
|
||||
}
|
||||
|
||||
for k, v := range t.html.funcster.funcMap {
|
||||
t.amberFuncMap[k] = v
|
||||
// Hacky, but we need to make sure that the func names are in the global map.
|
||||
amber.FuncMap[k] = func() string {
|
||||
panic("should never be invoked")
|
||||
}
|
||||
}
|
||||
amberMu.Unlock()
|
||||
|
||||
}
|
||||
|
||||
func (t *templateHandler) getTemplateHandler(name string) templateLoader {
|
||||
@@ -933,54 +912,11 @@ func (t *templateHandler) addTemplateFile(name, baseTemplatePath, path string) e
|
||||
ext := filepath.Ext(path)
|
||||
switch ext {
|
||||
case ".amber":
|
||||
// Only HTML support for Amber
|
||||
withoutExt := strings.TrimSuffix(name, filepath.Ext(name))
|
||||
templateName := withoutExt + ".html"
|
||||
b, err := afero.ReadFile(t.Layouts.Fs, path)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
amberMu.Lock()
|
||||
templ, err := t.compileAmberWithTemplate(b, path, t.html.t.New(templateName))
|
||||
amberMu.Unlock()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
typ := resolveTemplateType(name)
|
||||
|
||||
c, err := applyTemplateTransformersToHMLTTemplate(typ, templ)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if typ == templateShortcode {
|
||||
t.addShortcodeVariant(templateName, c.Info, templ)
|
||||
} else {
|
||||
t.templateInfo[name] = c.Info
|
||||
}
|
||||
|
||||
helpers.Deprecated("Amber templates are no longer supported.", "Use Go templates or a Hugo version <= 0.60.", true)
|
||||
return nil
|
||||
|
||||
case ".ace":
|
||||
// Only HTML support for Ace
|
||||
var innerContent, baseContent []byte
|
||||
innerContent, err := afero.ReadFile(t.Layouts.Fs, path)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if baseTemplatePath != "" {
|
||||
baseContent, err = afero.ReadFile(t.Layouts.Fs, baseTemplatePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return t.addAceTemplate(name, baseTemplatePath, path, baseContent, innerContent)
|
||||
helpers.Deprecated("ACE templates are no longer supported.", "Use Go templates or a Hugo version <= 0.60.", true)
|
||||
return nil
|
||||
default:
|
||||
|
||||
if baseTemplatePath != "" {
|
||||
|
Reference in New Issue
Block a user