From a82882fddc73eec3ac6dfb6a5ab84269e1a4f30e Mon Sep 17 00:00:00 2001 From: Marcel van der Boom Date: Tue, 20 Nov 2018 21:51:39 +0100 Subject: [PATCH] Put the highlight logic into one common template It now loads unconditionally and highlights all code blocks. TODO: optimize to not load when there are no blocks --- templates.go | 4 ++++ templates/collection-post.tmpl | 13 ++----------- templates/collection-tags.tmpl | 14 ++------------ templates/collection.tmpl | 14 +++----------- templates/include/render.tmpl | 14 ++++++++++++++ templates/post.tmpl | 17 ++--------------- 6 files changed, 27 insertions(+), 49 deletions(-) create mode 100644 templates/include/render.tmpl diff --git a/templates.go b/templates.go index 413f76a..9c2f1d3 100644 --- a/templates.go +++ b/templates.go @@ -55,12 +55,14 @@ func initTemplate(name string) { 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"), )) } @@ -74,6 +76,7 @@ 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"), )) } @@ -87,6 +90,7 @@ func initUserPage(path, key string) { path, filepath.Join(templatesDir, "user", "include", "header.tmpl"), filepath.Join(templatesDir, "user", "include", "footer.tmpl"), + filepath.Join(templatesDir, "user", "include", "render.tmpl"), )) } diff --git a/templates/collection-post.tmpl b/templates/collection-post.tmpl index b3e04cc..5baea38 100644 --- a/templates/collection-post.tmpl +++ b/templates/collection-post.tmpl @@ -46,17 +46,8 @@ {{end}} - {{if .Collection.CodeHighlight}} - - - - {{end}} + + {{template "highlighting" .}} diff --git a/templates/collection-tags.tmpl b/templates/collection-tags.tmpl index 4c2a126..e5c5fdc 100644 --- a/templates/collection-tags.tmpl +++ b/templates/collection-tags.tmpl @@ -45,18 +45,8 @@ {{end}} - {{if .CodeHighlight}} - - - - {{end}} - + + {{template "highlighting" . }} diff --git a/templates/collection.tmpl b/templates/collection.tmpl index a3fe8f6..54f8b2f 100644 --- a/templates/collection.tmpl +++ b/templates/collection.tmpl @@ -44,17 +44,9 @@ {{end}} - {{if .CodeHighlight}} - - - - {{end}} + + {{template "highlighting" . }} + {{if or .IsOwner .SingleUser}}