Optimize template loading on non-post pages

Avoids loading render.tmpl where it isn't needed.
This commit is contained in:
Matt Baer 2018-11-23 12:14:37 -05:00
parent 246a6dc554
commit 03c36af2f9
1 changed files with 10 additions and 16 deletions

View File

@ -49,23 +49,19 @@ func initTemplate(name string) {
log.Info(" %s%s%s.tmpl", templatesDir, string(filepath.Separator), name)
}
files := []string{
filepath.Join(templatesDir, name+".tmpl"),
filepath.Join(templatesDir, "include", "footer.tmpl"),
filepath.Join(templatesDir, "base.tmpl"),
}
if name == "collection" || name == "collection-tags" {
// These pages list out collection posts, so we also parse templatesDir + "include/posts.tmpl"
templates[name] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
filepath.Join(templatesDir, name+".tmpl"),
filepath.Join(templatesDir, "include", "posts.tmpl"),
filepath.Join(templatesDir, "include", "footer.tmpl"),
filepath.Join(templatesDir, "include", "render.tmpl"),
filepath.Join(templatesDir, "base.tmpl"),
))
} else {
templates[name] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
filepath.Join(templatesDir, name+".tmpl"),
filepath.Join(templatesDir, "include", "footer.tmpl"),
filepath.Join(templatesDir, "include", "render.tmpl"),
filepath.Join(templatesDir, "base.tmpl"),
))
files = append(files, filepath.Join(templatesDir, "include", "posts.tmpl"))
}
if name == "collection" || name == "collection-tags" || name == "collection-post" || name == "post" {
files = append(files, filepath.Join(templatesDir, "include", "render.tmpl"))
}
templates[name] = template.Must(template.New("").Funcs(funcMap).ParseFiles(files...))
}
func initPage(path, key string) {
@ -76,7 +72,6 @@ func initPage(path, key string) {
pages[key] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
path,
filepath.Join(templatesDir, "include", "footer.tmpl"),
filepath.Join(templatesDir, "include", "render.tmpl"),
filepath.Join(templatesDir, "base.tmpl"),
))
}
@ -90,7 +85,6 @@ func initUserPage(path, key string) {
path,
filepath.Join(templatesDir, "user", "include", "header.tmpl"),
filepath.Join(templatesDir, "user", "include", "footer.tmpl"),
filepath.Join(templatesDir, "include", "render.tmpl"),
))
}