mirror of
https://github.com/aljazceru/njump.git
synced 2026-02-23 15:04:22 +01:00
strip image and video urls from text if they are at the end of content.
This commit is contained in:
14
data.go
14
data.go
@@ -145,7 +145,7 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
||||
}
|
||||
case 1, 7, 30023, 30024:
|
||||
typ = "note"
|
||||
content = event.Content
|
||||
content = strings.TrimSpace(event.Content)
|
||||
parentNevent = getParentNevent(event)
|
||||
case 6:
|
||||
typ = "note"
|
||||
@@ -176,6 +176,7 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
||||
}
|
||||
kindNIP := kindNIPs[event.Kind]
|
||||
|
||||
// match image or video urls
|
||||
urls := urlMatcher.FindAllString(event.Content, -1)
|
||||
var image string
|
||||
var video string
|
||||
@@ -200,6 +201,17 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
||||
}
|
||||
}
|
||||
|
||||
// if these urls are at the end of the post, remove them from the content?
|
||||
var strippedContent string
|
||||
if image != "" && strings.HasSuffix(content, image) {
|
||||
strippedContent = strings.TrimSpace(content[0 : len(content)-len(image)])
|
||||
} else if video != "" && strings.HasSuffix(content, video) {
|
||||
strippedContent = strings.TrimSpace(content[0 : len(content)-len(video)])
|
||||
}
|
||||
if strippedContent != "" {
|
||||
content = strippedContent
|
||||
}
|
||||
|
||||
npubShort := npub[:8] + "…" + npub[len(npub)-4:]
|
||||
authorLong := npub
|
||||
authorShort := npubShort
|
||||
|
||||
@@ -157,7 +157,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
} else {
|
||||
// otherwise replace npub/nprofiles with names and trim length
|
||||
res := replaceUserReferencesWithNames(r.Context(), []string{data.event.Content})
|
||||
res := replaceUserReferencesWithNames(r.Context(), []string{data.content})
|
||||
description = res[0]
|
||||
if len(description) > 240 {
|
||||
description = description[:240]
|
||||
|
||||
Reference in New Issue
Block a user