mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
Improve author's citation in highlights
This commit is contained in:
17
data.go
17
data.go
@@ -135,11 +135,6 @@ func grabData(ctx context.Context, code string, withRelays bool) (Data, error) {
|
|||||||
case 9802:
|
case 9802:
|
||||||
data.templateId = Highlight
|
data.templateId = Highlight
|
||||||
data.content = event.Content
|
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 {
|
if sourceEvent := event.Tags.Find("e"); sourceEvent != nil {
|
||||||
data.Kind9802Metadata.SourceEvent = sourceEvent[1]
|
data.Kind9802Metadata.SourceEvent = sourceEvent[1]
|
||||||
data.Kind9802Metadata.SourceName = "#" + shortenString(sourceEvent[1], 8, 4)
|
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]
|
data.Kind9802Metadata.SourceName = sourceUrl[1]
|
||||||
}
|
}
|
||||||
if data.Kind9802Metadata.SourceEvent != "" {
|
if data.Kind9802Metadata.SourceEvent != "" {
|
||||||
|
// Retrieve the title
|
||||||
sourceEvent, _, _ := getEvent(ctx, data.Kind9802Metadata.SourceEvent, withRelays)
|
sourceEvent, _, _ := getEvent(ctx, data.Kind9802Metadata.SourceEvent, withRelays)
|
||||||
if title := sourceEvent.Tags.Find("title"); title != nil {
|
if title := sourceEvent.Tags.Find("title"); title != nil {
|
||||||
data.Kind9802Metadata.SourceName = title[1]
|
data.Kind9802Metadata.SourceName = title[1]
|
||||||
} else {
|
} 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 {
|
if context := event.Tags.Find("context"); context != nil {
|
||||||
data.Kind9802Metadata.Context = context[1]
|
data.Kind9802Metadata.Context = context[1]
|
||||||
|
|||||||
@@ -27,12 +27,15 @@ templ highlightInnerBlock(params HighlightPageParams) {
|
|||||||
} else {
|
} else {
|
||||||
@templ.Raw(params.Content)
|
@templ.Raw(params.Content)
|
||||||
}
|
}
|
||||||
<footer class="text-base mt-4">
|
<footer class="flex text-base mt-4">
|
||||||
—
|
<span>—</span>
|
||||||
if params.HighlightEvent.Author.Name != "" {
|
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 != "" {
|
if params.HighlightEvent.SourceURL != "" {
|
||||||
<a href={ templ.SafeURL(params.HighlightEvent.SourceURL) }>{ params.HighlightEvent.SourceName }</a>
|
<a href={ templ.SafeURL(params.HighlightEvent.SourceURL) }>{ params.HighlightEvent.SourceName }</a>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user