Skip to content

Commit

Permalink
embedr: improved HTML snippet, with links (#3559)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnewbold authored Apr 15, 2024
1 parent 4b69948 commit f265d65
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions bskyweb/cmd/embedr/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ func (srv *Server) postEmbedHTML(postView *appbsky.FeedDefs_PostView) (string, e
return "", err
}

const tpl = `<blockquote class="bluesky-embed" data-bluesky-uri="{{ .PostURI }}" data-bluesky-cid="{{ .PostCID }}"><p{{ if .PostLang }} lang="{{ .PostLang }}"{{ end }}>{{ .PostText }}</p>&mdash; {{ .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>&mdash; <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)
if err != nil {
log.Error("template parse error", "err", err)
return "", err
}

sortAt := postView.IndexedAt
createdAt, err := syntax.ParseDatetime(post.CreatedAt)
if nil == err && createdAt.String() < sortAt {
sortAt = createdAt.String()
}

var lang string
if len(post.Langs) > 0 {
lang = post.Langs[0]
Expand All @@ -41,23 +47,25 @@ func (srv *Server) postEmbedHTML(postView *appbsky.FeedDefs_PostView) (string, e
} else {
authorName = fmt.Sprintf("@%s", postView.Author.Handle)
}
fmt.Println(postView.Uri)
fmt.Println(fmt.Sprintf("%s", postView.Uri))
data := struct {
PostURI template.URL
PostCID string
PostLang string
PostText string
PostAuthor string
PostIndexedAt string
ProfileURL template.URL
PostURL template.URL
WidgetURL template.URL
}{
PostURI: template.URL(postView.Uri),
PostCID: postView.Cid,
PostLang: lang,
PostText: post.Text,
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"),
}

Expand Down

0 comments on commit f265d65

Please sign in to comment.