Improve author's citation in highlights

This commit is contained in:
dtonon
2025-04-03 20:38:07 +02:00
parent 09effa2701
commit 314b7a24e7
2 changed files with 18 additions and 10 deletions

17
data.go
View File

@@ -135,11 +135,6 @@ func grabData(ctx context.Context, code string, withRelays bool) (Data, error) {
case 9802:
data.templateId = Highlight
data.content = event.Content
if author := event.Tags.Find("p"); author != nil {
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
defer cancel()
data.Kind9802Metadata.Author = sys.FetchProfileMetadata(ctx, author[1])
}
if sourceEvent := event.Tags.Find("e"); sourceEvent != nil {
data.Kind9802Metadata.SourceEvent = sourceEvent[1]
data.Kind9802Metadata.SourceName = "#" + shortenString(sourceEvent[1], 8, 4)
@@ -157,12 +152,22 @@ func grabData(ctx context.Context, code string, withRelays bool) (Data, error) {
data.Kind9802Metadata.SourceName = sourceUrl[1]
}
if data.Kind9802Metadata.SourceEvent != "" {
// Retrieve the title
sourceEvent, _, _ := getEvent(ctx, data.Kind9802Metadata.SourceEvent, withRelays)
if title := sourceEvent.Tags.Find("title"); title != nil {
data.Kind9802Metadata.SourceName = title[1]
} else {
data.Kind9802Metadata.SourceName = "#" + shortenString(data.Kind9802Metadata.SourceEvent, 8, 4)
data.Kind9802Metadata.SourceName = "Note dated " + sourceEvent.CreatedAt.Time().Format("January 1, 2006 15:04")
}
// Retrieve the author using the event, ignore the `p` tag in the highlight event
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
defer cancel()
data.Kind9802Metadata.Author = sys.FetchProfileMetadata(ctx, sourceEvent.PubKey)
}
if author := event.Tags.Find("p"); author != nil {
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
defer cancel()
data.Kind9802Metadata.Author = sys.FetchProfileMetadata(ctx, author[1])
}
if context := event.Tags.Find("context"); context != nil {
data.Kind9802Metadata.Context = context[1]

View File

@@ -27,12 +27,15 @@ templ highlightInnerBlock(params HighlightPageParams) {
} else {
@templ.Raw(params.Content)
}
<footer class="text-base mt-4">
<footer class="flex text-base mt-4">
<span>—</span>
if params.HighlightEvent.Author.Name != "" {
{ params.HighlightEvent.Author.Name + "," }
<a href={ "https://njump.me/" + templ.SafeURL(params.HighlightEvent.Author.Npub()) } class="flex ml-2">
<img src={ params.HighlightEvent.Author.Picture } class="h-6 m-0 mr-1 rounded-full"/>
{ params.HighlightEvent.Author.Name }
</a>,
}
<cite>
<cite class="ml-2">
if params.HighlightEvent.SourceURL != "" {
<a href={ templ.SafeURL(params.HighlightEvent.SourceURL) }>{ params.HighlightEvent.SourceName }</a>
}