From c612dfc883d6c14adc88f2ea18410a6fde42895f Mon Sep 17 00:00:00 2001
From: Jan-Lukas Else
Date: Wed, 21 Apr 2021 20:17:26 +0200
Subject: [PATCH] Show link to comments in header only if enabled
---
render.go | 16 ++++++++--------
templates/comment.gohtml | 2 +-
templates/header.gohtml | 2 +-
templates/post.gohtml | 2 +-
4 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/render.go b/render.go
index 025bfe9..31e9126 100644
--- a/render.go
+++ b/render.go
@@ -156,9 +156,6 @@ func initRendering() error {
}
return parsed
},
- "commentsenabled": func(blog *configBlog) bool {
- return blog.Comments != nil && blog.Comments.Enabled
- },
"mentions": func(absolute string) []*mention {
mentions, _ := getWebmentions(&webmentionsRequestConfig{
target: absolute,
@@ -193,11 +190,12 @@ func initRendering() error {
}
type renderData struct {
- BlogString string
- Canonical string
- Blog *configBlog
- Data interface{}
- LoggedIn bool
+ BlogString string
+ Canonical string
+ Blog *configBlog
+ Data interface{}
+ LoggedIn bool
+ CommentsEnabled bool
}
func render(w http.ResponseWriter, r *http.Request, template string, data *renderData) {
@@ -225,6 +223,8 @@ func render(w http.ResponseWriter, r *http.Request, template string, data *rende
if loggedIn, ok := r.Context().Value(loggedInKey).(bool); ok && loggedIn {
data.LoggedIn = true
}
+ // Check if comments enabled
+ data.CommentsEnabled = data.Blog.Comments != nil && data.Blog.Comments.Enabled
// Minify and write response
mw := minifier.Writer(contentTypeHTML, w)
defer func() {
diff --git a/templates/comment.gohtml b/templates/comment.gohtml
index 9d3515e..38a1fb1 100644
--- a/templates/comment.gohtml
+++ b/templates/comment.gohtml
@@ -13,7 +13,7 @@
{{ html .Data.Comment }}
- {{ if commentsenabled .Blog }}
+ {{ if .CommentsEnabled }}
{{ include "interactions" . }}
{{ end }}
{{ end }}
diff --git a/templates/header.gohtml b/templates/header.gohtml
index e6eea14..f72adb3 100644
--- a/templates/header.gohtml
+++ b/templates/header.gohtml
@@ -12,7 +12,7 @@
{{ string .Blog.Lang "editor" }}
• {{ string .Blog.Lang "notifications" }}
• {{ string .Blog.Lang "webmentions" }}
- • {{ string .Blog.Lang "comments" }}
+ {{ if .CommentsEnabled }}• {{ string .Blog.Lang "comments" }}{{ end }}
• {{ string .Blog.Lang "logout" }}
{{ end }}
diff --git a/templates/post.gohtml b/templates/post.gohtml
index cdfe6ea..9e42270 100644
--- a/templates/post.gohtml
+++ b/templates/post.gohtml
@@ -41,7 +41,7 @@
{{ end }}
- {{ if commentsenabled .Blog }}
+ {{ if .CommentsEnabled }}
{{ include "interactions" . }}
{{ end }}
{{ end }}