GoBlog/render.go

38 lines
722 B
Go
Raw Normal View History

2020-07-31 13:48:01 +00:00
package main
import (
"html/template"
"log"
)
const templatePostName = "post.gohtml"
const templateRedirectName = "redirect.gohtml"
var templates *template.Template
func initRendering() {
templateFunctions := template.FuncMap{
"blog": func() *configBlog {
return appConfig.blog
},
"md": func(content string) template.HTML {
htmlContent, err := renderMarkdown(content)
if err != nil {
log.Fatal(err)
return ""
}
return template.HTML(htmlContent)
},
"title": func(post Post) string {
return post.Parameters["title"]
},
}
var err error
templates, err = template.New("templates").Funcs(templateFunctions).ParseGlob("templates/*.gohtml")
if err != nil {
log.Fatal(err)
}
}