embedr: improved HTML snippet, with links (#3559)
parent
4b69948366
commit
f265d65a18
|
@ -23,7 +23,7 @@ func (srv *Server) postEmbedHTML(postView *appbsky.FeedDefs_PostView) (string, e
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
const tpl = `<blockquote class="bluesky-embed" data-bluesky-uri="{{ .PostURI }}" data-bluesky-cid="{{ .PostCID }}"><p{{ if .PostLang }} lang="{{ .PostLang }}"{{ end }}>{{ .PostText }}</p>— {{ .PostAuthor }} {{ .PostIndexedAt }}</blockquote><script async src="{{ .WidgetURL }}" charset="utf-8"></script>`
|
const tpl = `<blockquote class="bluesky-embed" data-bluesky-uri="{{ .PostURI }}" data-bluesky-cid="{{ .PostCID }}"><p{{ if .PostLang }} lang="{{ .PostLang }}"{{ end }}>{{ .PostText }}</p>— <a href="{{ .ProfileURL }}">{{ .PostAuthor }}</a> <a href="{{ .PostURL }}">{{ .PostIndexedAt }}</a></blockquote><script async src="{{ .WidgetURL }}" charset="utf-8"></script>`
|
||||||
|
|
||||||
t, err := template.New("snippet").Parse(tpl)
|
t, err := template.New("snippet").Parse(tpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,6 +31,12 @@ func (srv *Server) postEmbedHTML(postView *appbsky.FeedDefs_PostView) (string, e
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortAt := postView.IndexedAt
|
||||||
|
createdAt, err := syntax.ParseDatetime(post.CreatedAt)
|
||||||
|
if nil == err && createdAt.String() < sortAt {
|
||||||
|
sortAt = createdAt.String()
|
||||||
|
}
|
||||||
|
|
||||||
var lang string
|
var lang string
|
||||||
if len(post.Langs) > 0 {
|
if len(post.Langs) > 0 {
|
||||||
lang = post.Langs[0]
|
lang = post.Langs[0]
|
||||||
|
@ -41,8 +47,6 @@ func (srv *Server) postEmbedHTML(postView *appbsky.FeedDefs_PostView) (string, e
|
||||||
} else {
|
} else {
|
||||||
authorName = fmt.Sprintf("@%s", postView.Author.Handle)
|
authorName = fmt.Sprintf("@%s", postView.Author.Handle)
|
||||||
}
|
}
|
||||||
fmt.Println(postView.Uri)
|
|
||||||
fmt.Println(fmt.Sprintf("%s", postView.Uri))
|
|
||||||
data := struct {
|
data := struct {
|
||||||
PostURI template.URL
|
PostURI template.URL
|
||||||
PostCID string
|
PostCID string
|
||||||
|
@ -50,6 +54,8 @@ func (srv *Server) postEmbedHTML(postView *appbsky.FeedDefs_PostView) (string, e
|
||||||
PostText string
|
PostText string
|
||||||
PostAuthor string
|
PostAuthor string
|
||||||
PostIndexedAt string
|
PostIndexedAt string
|
||||||
|
ProfileURL template.URL
|
||||||
|
PostURL template.URL
|
||||||
WidgetURL template.URL
|
WidgetURL template.URL
|
||||||
}{
|
}{
|
||||||
PostURI: template.URL(postView.Uri),
|
PostURI: template.URL(postView.Uri),
|
||||||
|
@ -57,7 +63,9 @@ func (srv *Server) postEmbedHTML(postView *appbsky.FeedDefs_PostView) (string, e
|
||||||
PostLang: lang,
|
PostLang: lang,
|
||||||
PostText: post.Text,
|
PostText: post.Text,
|
||||||
PostAuthor: authorName,
|
PostAuthor: authorName,
|
||||||
PostIndexedAt: postView.IndexedAt, // TODO: createdAt?
|
PostIndexedAt: sortAt,
|
||||||
|
ProfileURL: template.URL(fmt.Sprintf("https://bsky.app/profile/%s?ref_src=embed", aturi.Authority())),
|
||||||
|
PostURL: template.URL(fmt.Sprintf("https://bsky.app/profile/%s/post/%s?ref_src=embed", aturi.Authority(), aturi.RecordKey())),
|
||||||
WidgetURL: template.URL("https://embed.bsky.app/static/embed.js"),
|
WidgetURL: template.URL("https://embed.bsky.app/static/embed.js"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue