diff options
Diffstat (limited to 'hugolib/alias.go')
-rw-r--r-- | hugolib/alias.go | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/hugolib/alias.go b/hugolib/alias.go index d5eb35777..d1a1b5534 100644 --- a/hugolib/alias.go +++ b/hugolib/alias.go @@ -22,6 +22,8 @@ import ( "runtime" "strings" + "github.com/spf13/hugo/tpl" + jww "github.com/spf13/jwalterweatherman" "github.com/spf13/hugo/helpers" @@ -35,18 +37,19 @@ const ( var defaultAliasTemplates *template.Template func init() { + //TODO(bep) consolidate defaultAliasTemplates = template.New("") template.Must(defaultAliasTemplates.New("alias").Parse(alias)) template.Must(defaultAliasTemplates.New("alias-xhtml").Parse(aliasXHtml)) } type aliasHandler struct { - Templates *template.Template + t tpl.TemplateHandler log *jww.Notepad allowRoot bool } -func newAliasHandler(t *template.Template, l *jww.Notepad, allowRoot bool) aliasHandler { +func newAliasHandler(t tpl.TemplateHandler, l *jww.Notepad, allowRoot bool) aliasHandler { return aliasHandler{t, l, allowRoot} } @@ -56,12 +59,19 @@ func (a aliasHandler) renderAlias(isXHTML bool, permalink string, page *Page) (i t = "alias-xhtml" } - template := defaultAliasTemplates - if a.Templates != nil { - template = a.Templates - t = "alias.html" + var templ *tpl.TemplateAdapter + + if a.t != nil { + templ = a.t.Lookup("alias.html") } + if templ == nil { + def := defaultAliasTemplates.Lookup(t) + if def != nil { + templ = &tpl.TemplateAdapter{Template: def} + } + + } data := struct { Permalink string Page *Page @@ -71,7 +81,7 @@ func (a aliasHandler) renderAlias(isXHTML bool, permalink string, page *Page) (i } buffer := new(bytes.Buffer) - err := template.ExecuteTemplate(buffer, t, data) + err := templ.Execute(buffer, data) if err != nil { return nil, err } @@ -83,8 +93,7 @@ func (s *Site) writeDestAlias(path, permalink string, p *Page) (err error) { } func (s *Site) publishDestAlias(allowRoot bool, path, permalink string, p *Page) (err error) { - - handler := newAliasHandler(s.Tmpl.Lookup("alias.html"), s.Log, allowRoot) + handler := newAliasHandler(s.Tmpl, s.Log, allowRoot) isXHTML := strings.HasSuffix(path, ".xhtml") |