Add and document post parameter to disable interactions (#21)

pull/35/head
Jan-Lukas Else 1 month ago
parent a45d28d04f
commit 0a835b5f61
  1. 10
      comments.go
  2. 33
      comments_test.go
  3. 10
      docs/usage.md
  4. 2
      go.mod
  5. 4
      go.sum
  6. 3
      render.go
  7. 12
      ui.go

@ -146,3 +146,13 @@ func (db *database) deleteComment(id int) error {
_, err := db.Exec("delete from comments where id = @id", sql.Named("id", id))
return err
}
func (a *goBlog) commentsEnabledForBlog(blog *configBlog) bool {
return blog.Comments != nil && blog.Comments.Enabled
}
const commentsPostParam = "comments"
func (a *goBlog) commentsEnabledForPost(post *post) bool {
return post != nil && a.commentsEnabledForBlog(a.getBlogFromPost(post)) && post.firstParameter(commentsPostParam) != "false"
}

@ -164,3 +164,36 @@ func Test_comments(t *testing.T) {
})
}
func Test_commentsEnabled(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
err := app.initConfig(false)
require.NoError(t, err)
assert.False(t, app.commentsEnabledForPost(&post{
Blog: app.cfg.DefaultBlog,
}))
app.cfg.Blogs[app.cfg.DefaultBlog].Comments = &configComments{
Enabled: true,
}
assert.True(t, app.commentsEnabledForPost(&post{
Blog: app.cfg.DefaultBlog,
}))
assert.True(t, app.commentsEnabledForPost(&post{
Blog: app.cfg.DefaultBlog,
Parameters: map[string][]string{
"comments": {"true"},
},
}))
assert.False(t, app.commentsEnabledForPost(&post{
Blog: app.cfg.DefaultBlog,
Parameters: map[string][]string{
"comments": {"false"},
},
}))
}

@ -47,4 +47,12 @@ GoBlog can be configured to provide a Tor Hidden Service. This is useful if you
## Reactions
It's possible to enable post reactions. GoBlog currently has a hardcoded list of reactions: "❤", "👍", "👎", "😂" and "😱". If enabled, users can react to a post by clicking on the reaction button below the post. If you want to disable reactions for a single post, you can set the `reactions` parameter to `false` in the post's metadata.
It's possible to enable post reactions. GoBlog currently has a hardcoded list of reactions: "❤", "👍", "👎", "😂" and "😱". If enabled, users can react to a post by clicking on the reaction button below the post. If you want to disable reactions for a single post, you can set the `reactions` parameter to `false` in the post's metadata.
## Comments and interactions
GoBlog has a comment system. That can be enable using the configuration. See the `example-config.yml` file for how to configure it.
All comments and interactions (Webmentions) have to be approved manually using the UI at `/webmention`. To completely delete a comment, delete the entry from the Webmention UI and also delete the comment from `/comment`.
To disable showing comments and interactions on a single post, add the parameter `comments` with the value `false` to the post's metadata.

@ -59,7 +59,7 @@ require (
// master
github.com/yuin/goldmark-emoji v1.0.2-0.20210607094911-0487583eca38
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/net v0.0.0-20220811182439-13a9a731de15
golang.org/x/net v0.0.0-20220812174116-3211cb980234
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/text v0.3.7
gopkg.in/yaml.v3 v3.0.1

@ -619,8 +619,8 @@ golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220811182439-13a9a731de15 h1:cik0bxZUSJVDyaHf1hZPSDsU8SZHGQZQMeueXCE7yBQ=
golang.org/x/net v0.0.0-20220811182439-13a9a731de15/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E=
golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

@ -15,7 +15,6 @@ type renderData struct {
Blog *configBlog
User *configUser
Data any
CommentsEnabled bool
WebmentionReceivingEnabled bool
TorUsed bool
EasterEgg bool
@ -79,8 +78,6 @@ func (a *goBlog) checkRenderData(r *http.Request, data *renderData) {
if torUsed, ok := r.Context().Value(torUsedKey).(bool); ok && torUsed {
data.TorUsed = true
}
// Check if comments enabled
data.CommentsEnabled = data.Blog.Comments != nil && data.Blog.Comments.Enabled
// Check if able to receive webmentions
data.WebmentionReceivingEnabled = a.cfg.Webmention == nil || !a.cfg.Webmention.DisableReceiving
// Easter egg

12
ui.go

@ -139,7 +139,7 @@ func (a *goBlog) renderBase(hb *htmlbuilder.HtmlBuilder, rd *renderData, title,
hb.WriteEscaped(a.ts.GetTemplateStringVariant(rd.Blog.Lang, "webmentions"))
hb.WriteElementClose("a")
}
if rd.CommentsEnabled {
if a.commentsEnabledForBlog(rd.Blog) {
hb.WriteUnescaped(" • ")
hb.WriteElementOpen("a", "href", "/comment")
hb.WriteEscaped(a.ts.GetTemplateStringVariant(rd.Blog.Lang, "comments"))
@ -358,7 +358,7 @@ func (a *goBlog) renderComment(h *htmlbuilder.HtmlBuilder, rd *renderData) {
hb.WriteElementClose("p")
hb.WriteElementClose("main")
// Interactions
if rd.CommentsEnabled {
if a.commentsEnabledForBlog(rd.Blog) {
a.renderInteractions(hb, rd)
}
},
@ -467,7 +467,7 @@ func (a *goBlog) renderBlogStats(hb *htmlbuilder.HtmlBuilder, rd *renderData) {
hb.WriteElementClose("script")
hb.WriteElementClose("main")
// Interactions
if rd.CommentsEnabled {
if a.commentsEnabledForBlog(rd.Blog) {
a.renderInteractions(hb, rd)
}
},
@ -626,7 +626,7 @@ func (a *goBlog) renderGeoMap(hb *htmlbuilder.HtmlBuilder, rd *renderData) {
hb.WriteElementClose("script")
}
hb.WriteElementClose("main")
if rd.CommentsEnabled {
if a.commentsEnabledForBlog(rd.Blog) {
a.renderInteractions(hb, rd)
}
},
@ -701,7 +701,7 @@ func (a *goBlog) renderBlogroll(hb *htmlbuilder.HtmlBuilder, rd *renderData) {
}
hb.WriteElementClose("main")
// Interactions
if rd.CommentsEnabled {
if a.commentsEnabledForBlog(rd.Blog) {
a.renderInteractions(hb, rd)
}
},
@ -980,7 +980,7 @@ func (a *goBlog) renderPost(hb *htmlbuilder.HtmlBuilder, rd *renderData) {
hb.WriteElementClose("div")
}
// Comments
if rd.CommentsEnabled {
if a.commentsEnabledForPost(p) {
a.renderInteractions(hb, rd)
}
},

Loading…
Cancel
Save