mirror of https://github.com/jlelse/GoBlog
Allow comments on comments
This commit is contained in:
parent
66ada4c0ae
commit
e434103fc1
21
comments.go
21
comments.go
|
@ -4,7 +4,9 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
|
@ -41,6 +43,7 @@ func serveComment(blog string) func(http.ResponseWriter, *http.Request) {
|
|||
w.Header().Set("X-Robots-Tag", "noindex")
|
||||
render(w, templateComment, &renderData{
|
||||
BlogString: blog,
|
||||
Canonical: appConfig.Server.PublicAddress + appConfig.Blogs[blog].getRelativePath(fmt.Sprintf("/comment/%d", id)),
|
||||
Data: comment,
|
||||
})
|
||||
}
|
||||
|
@ -93,22 +96,16 @@ func checkCommentTarget(w http.ResponseWriter, r *http.Request) string {
|
|||
if target == "" {
|
||||
serveError(w, r, "No target specified", http.StatusBadRequest)
|
||||
return ""
|
||||
} else if !strings.HasPrefix(target, appConfig.Server.PublicAddress) {
|
||||
serveError(w, r, "Bad target", http.StatusBadRequest)
|
||||
return ""
|
||||
}
|
||||
postExists := 0
|
||||
row, err := appDbQueryRow("select exists(select 1 from posts where path = @path)", sql.Named("path", target))
|
||||
targetURL, err := url.Parse(target)
|
||||
if err != nil {
|
||||
serveError(w, r, err.Error(), http.StatusInternalServerError)
|
||||
serveError(w, r, err.Error(), http.StatusBadRequest)
|
||||
return ""
|
||||
}
|
||||
if err = row.Scan(&postExists); err != nil {
|
||||
serveError(w, r, err.Error(), http.StatusInternalServerError)
|
||||
return ""
|
||||
}
|
||||
if postExists != 1 {
|
||||
serveError(w, r, "Post does not exist", http.StatusBadRequest)
|
||||
return ""
|
||||
}
|
||||
return target
|
||||
return targetURL.Path
|
||||
}
|
||||
|
||||
func commentsAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
3
go.mod
3
go.mod
|
@ -10,7 +10,7 @@ require (
|
|||
github.com/caddyserver/certmagic v0.12.0
|
||||
github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/go-chi/chi v1.5.1
|
||||
github.com/go-chi/chi v1.5.2
|
||||
github.com/go-fed/httpsig v1.1.0
|
||||
github.com/go-sql-driver/mysql v1.5.0 // indirect
|
||||
github.com/gofrs/flock v0.8.0 // indirect
|
||||
|
@ -44,6 +44,7 @@ require (
|
|||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/viper v1.7.1
|
||||
github.com/tdewolff/minify/v2 v2.9.12
|
||||
github.com/tdewolff/parse/v2 v2.5.10 // indirect
|
||||
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80
|
||||
github.com/vcraescu/go-paginator v1.0.1-0.20201114172518-2cfc59fe05c2
|
||||
github.com/yuin/goldmark v1.3.2
|
||||
|
|
6
go.sum
6
go.sum
|
@ -66,8 +66,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
|
|||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-chi/chi v1.5.1 h1:kfTK3Cxd/dkMu/rKs5ZceWYp+t5CtiE7vmaTv3LjC6w=
|
||||
github.com/go-chi/chi v1.5.1/go.mod h1:REp24E+25iKvxgeTfHmdUoL5x15kBiDBlnIl5bCwe2k=
|
||||
github.com/go-chi/chi v1.5.2 h1:YcLIBANL4OTaAOcTdp//sskGa0yGACQMCtbnr7YEn0Q=
|
||||
github.com/go-chi/chi v1.5.2/go.mod h1:REp24E+25iKvxgeTfHmdUoL5x15kBiDBlnIl5bCwe2k=
|
||||
github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
|
||||
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
|
@ -288,6 +288,8 @@ github.com/tdewolff/minify/v2 v2.9.12 h1:BKnbg3kcAuTLAhDeF3vSUxjvyj5lBRxaBvgxGCV
|
|||
github.com/tdewolff/minify/v2 v2.9.12/go.mod h1:yuntVVAFuGyi9VmiRoUqAYEQnFCGO929ytj2ITMZuB8=
|
||||
github.com/tdewolff/parse/v2 v2.5.9 h1:9wCXRT3OcgYDNatgU+HUTOoGhE9WcnY5UxLNoJUe1yw=
|
||||
github.com/tdewolff/parse/v2 v2.5.9/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho=
|
||||
github.com/tdewolff/parse/v2 v2.5.10 h1:vj35n+ljq8LuYUx436s4qB18wuwP7thrLv+t1syE39M=
|
||||
github.com/tdewolff/parse/v2 v2.5.10/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho=
|
||||
github.com/tdewolff/test v1.0.6 h1:76mzYJQ83Op284kMT+63iCNCI7NEERsIN8dLM+RiKr4=
|
||||
github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
|
|
16
render.go
16
render.go
|
@ -86,14 +86,6 @@ func initRendering() error {
|
|||
"translations": func(p *post) []*post {
|
||||
return p.translations()
|
||||
},
|
||||
"postmentions": func(p *post) []*mention {
|
||||
mentions, _ := getWebmentions(&webmentionsRequestConfig{
|
||||
target: p.fullURL(),
|
||||
status: webmentionStatusApproved,
|
||||
asc: true,
|
||||
})
|
||||
return mentions
|
||||
},
|
||||
"shorturl": func(p *post) string {
|
||||
return p.shortURL()
|
||||
},
|
||||
|
@ -208,6 +200,14 @@ func initRendering() error {
|
|||
"commentsenabled": func(blog *configBlog) bool {
|
||||
return blog.Comments != nil && blog.Comments.Enabled
|
||||
},
|
||||
"mentions": func(absolute string) []*mention {
|
||||
mentions, _ := getWebmentions(&webmentionsRequestConfig{
|
||||
target: absolute,
|
||||
status: webmentionStatusApproved,
|
||||
asc: true,
|
||||
})
|
||||
return mentions
|
||||
},
|
||||
}
|
||||
|
||||
templates = map[string]*template.Template{}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{{ define "title" }}
|
||||
<title>{{ string .Blog.Lang "acommentby" }} {{ .Data.Name }} - {{ .Blog.Title }}</title>
|
||||
<title>{{ string .Blog.Lang "acommentby" }} {{ .Data.Name }}</title>
|
||||
{{ end }}
|
||||
|
||||
{{ define "main" }}
|
||||
|
@ -13,6 +13,9 @@
|
|||
{{ html .Data.Comment }}
|
||||
</div>
|
||||
</main>
|
||||
{{ if commentsenabled .Blog }}
|
||||
{{ include "interactions" . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "comment" }}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
{{ define "interactions" }}
|
||||
<details class="p" id="interactions">
|
||||
<summary><b>{{ string .Blog.Lang "interactions" }}</b></summary>
|
||||
{{ $postperma := ( absolute .Data.Path ) }}
|
||||
{{ $mentions := ( postmentions .Data ) }}
|
||||
{{ if $mentions }}
|
||||
{{ with ( mentions .Canonical ) }}
|
||||
<ul>
|
||||
{{ range $i, $mention := $mentions }}
|
||||
{{ range $i, $mention := . }}
|
||||
<li><a href="{{$mention.Source}}" target="_blank" rel="nofollow noopener noreferrer ugc">
|
||||
{{ if $mention.Author }}
|
||||
{{ $mention.Author }}
|
||||
|
@ -19,11 +17,11 @@
|
|||
<form class="fw-form p" method="post" action="/webmention">
|
||||
<label for="wm-source" class="p">{{ string .Blog.Lang "interactionslabel" }}</label>
|
||||
<input id="wm-source" type="url" name="source" placeholder="URL" required>
|
||||
<input type="hidden" name="target" value="{{ $postperma }}">
|
||||
<input type="hidden" name="target" value="{{ .Canonical }}">
|
||||
<input class="fw" type="submit" value="{{ string .Blog.Lang "send" }}">
|
||||
</form>
|
||||
<form class="fw-form p" method="post" action="{{ blogrelative .Blog "/comment" }}">
|
||||
<input type="hidden" name="target" value="{{ .Data.Path }}">
|
||||
<input type="hidden" name="target" value="{{ .Canonical }}">
|
||||
<input type="text" name="name" placeholder="{{ string .Blog.Lang "nameopt" }}">
|
||||
<input type="url" name="website" placeholder="{{ string .Blog.Lang "websiteopt" }}">
|
||||
<textarea name="comment" required placeholder="{{ string .Blog.Lang "comment" }}"></textarea>
|
||||
|
|
Loading…
Reference in New Issue