mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
@@ -14,6 +14,7 @@
|
||||
package tplimpl
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"path/filepath"
|
||||
|
||||
"strings"
|
||||
@@ -24,7 +25,8 @@ import (
|
||||
func (t *templateHandler) addAceTemplate(name, basePath, innerPath string, baseContent, innerContent []byte) error {
|
||||
t.checkState()
|
||||
var base, inner *ace.File
|
||||
name = name[:len(name)-len(filepath.Ext(innerPath))] + ".html"
|
||||
withoutExt := name[:len(name)-len(filepath.Ext(innerPath))]
|
||||
name = withoutExt + ".html"
|
||||
|
||||
// Fixes issue #1178
|
||||
basePath = strings.Replace(basePath, "\\", "/", -1)
|
||||
@@ -37,15 +39,29 @@ func (t *templateHandler) addAceTemplate(name, basePath, innerPath string, baseC
|
||||
base = ace.NewFile(innerPath, innerContent)
|
||||
inner = ace.NewFile("", []byte{})
|
||||
}
|
||||
|
||||
parsed, err := ace.ParseSource(ace.NewSource(base, inner, []*ace.File{}), nil)
|
||||
if err != nil {
|
||||
t.errors = append(t.errors, &templateErr{name: name, err: err})
|
||||
return err
|
||||
}
|
||||
|
||||
templ, err := ace.CompileResultWithTemplate(t.html.t.New(name), parsed, nil)
|
||||
if err != nil {
|
||||
t.errors = append(t.errors, &templateErr{name: name, err: err})
|
||||
return err
|
||||
}
|
||||
return applyTemplateTransformersToHMLTTemplate(templ)
|
||||
|
||||
if err := applyTemplateTransformersToHMLTTemplate(templ); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.Contains(name, "shortcodes") {
|
||||
// We need to keep track of one ot the output format's shortcode template
|
||||
// without knowing the rendering context.
|
||||
clone := template.Must(templ.Clone())
|
||||
t.html.t.AddParseTree(withoutExt, clone.Tree)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -622,7 +622,8 @@ func (t *templateHandler) addTemplateFile(name, baseTemplatePath, path string) e
|
||||
switch ext {
|
||||
case ".amber":
|
||||
// Only HTML support for Amber
|
||||
templateName := strings.TrimSuffix(name, filepath.Ext(name)) + ".html"
|
||||
withoutExt := strings.TrimSuffix(name, filepath.Ext(name))
|
||||
templateName := withoutExt + ".html"
|
||||
b, err := afero.ReadFile(t.Fs.Source, path)
|
||||
|
||||
if err != nil {
|
||||
@@ -636,7 +637,19 @@ func (t *templateHandler) addTemplateFile(name, baseTemplatePath, path string) e
|
||||
return err
|
||||
}
|
||||
|
||||
return applyTemplateTransformersToHMLTTemplate(templ)
|
||||
if err := applyTemplateTransformersToHMLTTemplate(templ); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.Contains(templateName, "shortcodes") {
|
||||
// We need to keep track of one ot the output format's shortcode template
|
||||
// without knowing the rendering context.
|
||||
clone := template.Must(templ.Clone())
|
||||
t.html.t.AddParseTree(withoutExt, clone.Tree)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case ".ace":
|
||||
// Only HTML support for Ace
|
||||
var innerContent, baseContent []byte
|
||||
|
Reference in New Issue
Block a user