mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Revert "tpl: Rework to handle both text and HTML templates"
Will have to take another stab at this ...
This reverts commit 5c5efa03d2
.
Closes #3260
This commit is contained in:
@@ -188,7 +188,7 @@ func NewSite(cfg deps.DepsCfg) (*Site, error) {
|
||||
// NewSiteDefaultLang creates a new site in the default language.
|
||||
// The site will have a template system loaded and ready to use.
|
||||
// Note: This is mainly used in single site tests.
|
||||
func NewSiteDefaultLang(withTemplate ...func(templ tpl.TemplateHandler) error) (*Site, error) {
|
||||
func NewSiteDefaultLang(withTemplate ...func(templ tpl.Template) error) (*Site, error) {
|
||||
v := viper.New()
|
||||
loadDefaultSettingsFor(v)
|
||||
return newSiteForLang(helpers.NewDefaultLanguage(v), withTemplate...)
|
||||
@@ -197,15 +197,15 @@ func NewSiteDefaultLang(withTemplate ...func(templ tpl.TemplateHandler) error) (
|
||||
// NewEnglishSite creates a new site in English language.
|
||||
// The site will have a template system loaded and ready to use.
|
||||
// Note: This is mainly used in single site tests.
|
||||
func NewEnglishSite(withTemplate ...func(templ tpl.TemplateHandler) error) (*Site, error) {
|
||||
func NewEnglishSite(withTemplate ...func(templ tpl.Template) error) (*Site, error) {
|
||||
v := viper.New()
|
||||
loadDefaultSettingsFor(v)
|
||||
return newSiteForLang(helpers.NewLanguage("en", v), withTemplate...)
|
||||
}
|
||||
|
||||
// newSiteForLang creates a new site in the given language.
|
||||
func newSiteForLang(lang *helpers.Language, withTemplate ...func(templ tpl.TemplateHandler) error) (*Site, error) {
|
||||
withTemplates := func(templ tpl.TemplateHandler) error {
|
||||
func newSiteForLang(lang *helpers.Language, withTemplate ...func(templ tpl.Template) error) (*Site, error) {
|
||||
withTemplates := func(templ tpl.Template) error {
|
||||
for _, wt := range withTemplate {
|
||||
if err := wt(templ); err != nil {
|
||||
return err
|
||||
@@ -1906,14 +1906,13 @@ Your rendered home page is blank: /index.html is zero-length
|
||||
}
|
||||
|
||||
func (s *Site) renderForLayouts(name string, d interface{}, w io.Writer, layouts ...string) error {
|
||||
templ := s.findFirstTemplate(layouts...)
|
||||
if templ == nil {
|
||||
layout, found := s.findFirstLayout(layouts...)
|
||||
if !found {
|
||||
helpers.DistinctWarnLog.Printf("[%s] Unable to locate layout for %s: %s\n", s.Language.Lang, name, layouts)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := templ.Execute(w, d); err != nil {
|
||||
if err := s.renderThing(d, layout, w); err != nil {
|
||||
|
||||
// Behavior here should be dependent on if running in server or watch mode.
|
||||
helpers.DistinctErrorLog.Printf("Error while rendering %q: %s", name, err)
|
||||
@@ -1928,13 +1927,23 @@ func (s *Site) renderForLayouts(name string, d interface{}, w io.Writer, layouts
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Site) findFirstTemplate(layouts ...string) tpl.Template {
|
||||
func (s *Site) findFirstLayout(layouts ...string) (string, bool) {
|
||||
for _, layout := range layouts {
|
||||
if templ := s.Tmpl.Lookup(layout); templ != nil {
|
||||
return templ
|
||||
if s.Tmpl.Lookup(layout) != nil {
|
||||
return layout, true
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return "", false
|
||||
}
|
||||
|
||||
func (s *Site) renderThing(d interface{}, layout string, w io.Writer) error {
|
||||
|
||||
// If the template doesn't exist, then return, but leave the Writer open
|
||||
if templ := s.Tmpl.Lookup(layout); templ != nil {
|
||||
return templ.Execute(w, d)
|
||||
}
|
||||
return fmt.Errorf("Layout not found: %s", layout)
|
||||
|
||||
}
|
||||
|
||||
func (s *Site) publish(path string, r io.Reader) (err error) {
|
||||
|
Reference in New Issue
Block a user