Show comment threads

This commit is contained in:
Jan-Lukas Else 2021-11-18 22:56:30 +01:00
parent 8baf4877c1
commit 5760355769
3 changed files with 47 additions and 23 deletions

View File

@ -1,18 +1,9 @@
{{ define "interactions" }} {{ define "interactions" }}
<details class="p" id="interactions"> <details class="p" id="interactions">
<summary><b>{{ string .Blog.Lang "interactions" }}</b></summary> <summary><b>{{ string .Blog.Lang "interactions" }}</b></summary>
{{ $rd := . }}
{{ with ( mentions .Canonical ) }} {{ with ( mentions .Canonical ) }}
<ul> {{ include "mentions" $rd . }}
{{ range $i, $mention := . }}
<li><a href="{{$mention.Source}}" target="_blank" rel="nofollow noopener noreferrer ugc">
{{ if $mention.Author }}
{{ $mention.Author }}
{{ else }}
{{ $mention.Source }}
{{ end }}
</a>{{ with $mention.Title }} <b>{{.}}</b>{{ end }}{{ with $mention.Content }} <i>{{.}}</i>{{ end }}</li>
{{ end }}
</ul>
{{ end }} {{ end }}
<form class="fw p" method="post" action="/webmention"> <form class="fw p" method="post" action="/webmention">
<label for="wm-source" class="p">{{ string .Blog.Lang "interactionslabel" }}</label> <label for="wm-source" class="p">{{ string .Blog.Lang "interactionslabel" }}</label>

19
templates/mentions.gohtml Normal file
View File

@ -0,0 +1,19 @@
{{ define "mentions" }}
{{ $rd := . }}
<ul>
{{ range $i, $mention := .Data }}
<li>
<a href="{{$mention.Source}}" target="_blank" rel="nofollow noopener noreferrer ugc">
{{ if $mention.Author }}
{{ $mention.Author }}
{{ else }}
{{ $mention.Source }}
{{ end }}
</a>
{{ with $mention.Title }} <b>{{.}}</b>{{ end }}
{{ with $mention.Content }} <i>{{.}}</i>{{ end }}
{{ with $mention.Submentions }}{{ include "mentions" $rd . }}{{ end }}
</li>
{{ end }}
</ul>
{{ end }}

View File

@ -30,6 +30,7 @@ type mention struct {
Content string Content string
Author string Author string
Status webmentionStatus Status webmentionStatus
Submentions []*mention
} }
func (a *goBlog) initWebmention() { func (a *goBlog) initWebmention() {
@ -156,6 +157,7 @@ type webmentionsRequestConfig struct {
id int id int
asc bool asc bool
offset, limit int offset, limit int
submentions bool
} }
func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args []interface{}) { func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args []interface{}) {
@ -206,6 +208,17 @@ func (db *database) getWebmentions(config *webmentionsRequestConfig) ([]*mention
if err != nil { if err != nil {
return nil, err return nil, err
} }
if config.submentions {
m.Submentions, err = db.getWebmentions(&webmentionsRequestConfig{
target: m.Source,
submentions: true,
asc: config.asc,
status: config.status,
})
if err != nil {
return nil, err
}
}
mentions = append(mentions, m) mentions = append(mentions, m)
} }
return mentions, nil return mentions, nil
@ -216,6 +229,7 @@ func (db *database) getWebmentionsByAddress(address string) []*mention {
target: address, target: address,
status: webmentionStatusApproved, status: webmentionStatusApproved,
asc: true, asc: true,
submentions: true,
}) })
return mentions return mentions
} }