Show link to comments in header only if enabled

This commit is contained in:
Jan-Lukas Else 2021-04-21 20:17:26 +02:00
parent a24cad5699
commit c612dfc883
4 changed files with 11 additions and 11 deletions

View File

@ -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() {

View File

@ -13,7 +13,7 @@
{{ html .Data.Comment }}
</p>
</main>
{{ if commentsenabled .Blog }}
{{ if .CommentsEnabled }}
{{ include "interactions" . }}
{{ end }}
{{ end }}

View File

@ -12,7 +12,7 @@
<a href="{{ blogrelative .Blog "/editor" }}">{{ string .Blog.Lang "editor" }}</a>
&bull; <a href="/notifications">{{ string .Blog.Lang "notifications" }}</a>
&bull; <a href="/webmention">{{ string .Blog.Lang "webmentions" }}</a>
&bull; <a href="{{ blogrelative .Blog "/comment" }}">{{ string .Blog.Lang "comments" }}</a>
{{ if .CommentsEnabled }}&bull; <a href="{{ blogrelative .Blog "/comment" }}">{{ string .Blog.Lang "comments" }}</a>{{ end }}
&bull; <a href="/logout">{{ string .Blog.Lang "logout" }}</a>
</nav>
{{ end }}

View File

@ -41,7 +41,7 @@
</form>
</div>
{{ end }}
{{ if commentsenabled .Blog }}
{{ if .CommentsEnabled }}
{{ include "interactions" . }}
{{ end }}
{{ end }}