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" }}
<details class="p" id="interactions">
<summary><b>{{ string .Blog.Lang "interactions" }}</b></summary>
{{ $rd := . }}
{{ with ( mentions .Canonical ) }}
<ul>
{{ 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>
{{ include "mentions" $rd . }}
{{ end }}
<form class="fw p" method="post" action="/webmention">
<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

@ -21,15 +21,16 @@ const (
)
type mention struct {
ID int
Source string
NewSource string
Target string
Created int64
Title string
Content string
Author string
Status webmentionStatus
ID int
Source string
NewSource string
Target string
Created int64
Title string
Content string
Author string
Status webmentionStatus
Submentions []*mention
}
func (a *goBlog) initWebmention() {
@ -156,6 +157,7 @@ type webmentionsRequestConfig struct {
id int
asc bool
offset, limit int
submentions bool
}
func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args []interface{}) {
@ -206,6 +208,17 @@ func (db *database) getWebmentions(config *webmentionsRequestConfig) ([]*mention
if err != nil {
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)
}
return mentions, nil
@ -213,9 +226,10 @@ func (db *database) getWebmentions(config *webmentionsRequestConfig) ([]*mention
func (db *database) getWebmentionsByAddress(address string) []*mention {
mentions, _ := db.getWebmentions(&webmentionsRequestConfig{
target: address,
status: webmentionStatusApproved,
asc: true,
target: address,
status: webmentionStatusApproved,
asc: true,
submentions: true,
})
return mentions
}