ensure metadata is never nil again.

This commit is contained in:
fiatjaf
2023-11-22 11:45:38 -03:00
parent 3565a9d228
commit bccd22654c
4 changed files with 14 additions and 19 deletions

View File

@@ -134,7 +134,7 @@ type Data struct {
createdAt string createdAt string
modifiedAt string modifiedAt string
parentLink template.HTML parentLink template.HTML
metadata *sdk.ProfileMetadata metadata sdk.ProfileMetadata
authorRelays []string authorRelays []string
authorLong string authorLong string
authorShort string authorShort string
@@ -371,9 +371,7 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
author, relays, _ := getEvent(ctx, data.npub, relaysForNip19) author, relays, _ := getEvent(ctx, data.npub, relaysForNip19)
if author != nil { if author != nil {
data.metadata, _ = sdk.ParseMetadata(author) data.metadata, _ = sdk.ParseMetadata(author)
if data.metadata == nil { if data.metadata.Name != "" {
data.metadata = &sdk.ProfileMetadata{PubKey: data.event.PubKey}
} else {
data.authorLong = fmt.Sprintf("%s (%s)", data.metadata.Name, data.npub) data.authorLong = fmt.Sprintf("%s (%s)", data.metadata.Name, data.npub)
data.authorShort = fmt.Sprintf("%s (%s)", data.metadata.Name, data.npubShort) data.authorShort = fmt.Sprintf("%s (%s)", data.metadata.Name, data.npubShort)
} }

7
go.mod
View File

@@ -9,12 +9,12 @@ require (
github.com/fiatjaf/eventstore v0.2.6 github.com/fiatjaf/eventstore v0.2.6
github.com/fiatjaf/khatru v0.0.6 github.com/fiatjaf/khatru v0.0.6
github.com/fogleman/gg v1.3.0 github.com/fogleman/gg v1.3.0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/gomarkdown/markdown v0.0.0-20230322041520-c84983bdbf2a github.com/gomarkdown/markdown v0.0.0-20230322041520-c84983bdbf2a
github.com/kelseyhightower/envconfig v1.4.0 github.com/kelseyhightower/envconfig v1.4.0
github.com/lukevers/freetype-go v0.0.0-20150513150840-77e276735410
github.com/microcosm-cc/bluemonday v1.0.24 github.com/microcosm-cc/bluemonday v1.0.24
github.com/nbd-wtf/go-nostr v0.25.3 github.com/nbd-wtf/go-nostr v0.25.3
github.com/nbd-wtf/nostr-sdk v0.0.3 github.com/nbd-wtf/nostr-sdk v0.0.4
github.com/pelletier/go-toml v1.9.5 github.com/pelletier/go-toml v1.9.5
github.com/rs/cors v1.10.0 github.com/rs/cors v1.10.0
github.com/rs/zerolog v1.29.1 github.com/rs/zerolog v1.29.1
@@ -22,6 +22,7 @@ require (
github.com/texttheater/golang-levenshtein v1.0.1 github.com/texttheater/golang-levenshtein v1.0.1
github.com/tylermmorton/tmpl v0.0.0-20231025031313-5552ee818c6d github.com/tylermmorton/tmpl v0.0.0-20231025031313-5552ee818c6d
golang.org/x/exp v0.0.0-20231006140011-7918f672742d golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/image v0.14.0
mvdan.cc/xurls/v2 v2.5.0 mvdan.cc/xurls/v2 v2.5.0
) )
@@ -43,7 +44,6 @@ require (
github.com/gobwas/pool v0.2.1 // indirect github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.3.1 // indirect github.com/gobwas/ws v1.3.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/glog v1.1.2 // indirect github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect github.com/golang/protobuf v1.5.3 // indirect
@@ -65,7 +65,6 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.47.0 // indirect github.com/valyala/fasthttp v1.47.0 // indirect
go.opencensus.io v0.24.0 // indirect go.opencensus.io v0.24.0 // indirect
golang.org/x/image v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.14.0 // indirect golang.org/x/sys v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect google.golang.org/protobuf v1.31.0 // indirect

6
go.sum
View File

@@ -142,8 +142,6 @@ github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lukevers/freetype-go v0.0.0-20150513150840-77e276735410 h1:ED5jVfC//XhwaBl9B8nB+UQFvI/7Iee03tV4gRVWgMA=
github.com/lukevers/freetype-go v0.0.0-20150513150840-77e276735410/go.mod h1:cnsFc3HOpydgckvXF3xq4fvlLFOAuTh4VyJ118x8LQc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
@@ -154,8 +152,8 @@ github.com/microcosm-cc/bluemonday v1.0.24 h1:NGQoPtwGVcbGkKfvyYk1yRqknzBuoMiUrO
github.com/microcosm-cc/bluemonday v1.0.24/go.mod h1:ArQySAMps0790cHSkdPEJ7bGkF2VePWH773hsJNSHf8= github.com/microcosm-cc/bluemonday v1.0.24/go.mod h1:ArQySAMps0790cHSkdPEJ7bGkF2VePWH773hsJNSHf8=
github.com/nbd-wtf/go-nostr v0.25.3 h1:RPPh4cOosw0OZi5KG627pZ3GlKxiKsjARluzen/mB9g= github.com/nbd-wtf/go-nostr v0.25.3 h1:RPPh4cOosw0OZi5KG627pZ3GlKxiKsjARluzen/mB9g=
github.com/nbd-wtf/go-nostr v0.25.3/go.mod h1:bkffJI+x914sPQWum9ZRUn66D7NpDnAoWo1yICvj3/0= github.com/nbd-wtf/go-nostr v0.25.3/go.mod h1:bkffJI+x914sPQWum9ZRUn66D7NpDnAoWo1yICvj3/0=
github.com/nbd-wtf/nostr-sdk v0.0.3 h1:t6mly9gyzfJ2kLCtJsw9bYZxDwI5rHWORdcSQEu6l64= github.com/nbd-wtf/nostr-sdk v0.0.4 h1:vMCiYpFElKMHPXpZjFVEq4utoTLdTYbkqXVYH1/4uzs=
github.com/nbd-wtf/nostr-sdk v0.0.3/go.mod h1:KQZOtzcrXBlVhpZYG1tw83ADIONNMMPjUU3ZAH5U2RY= github.com/nbd-wtf/nostr-sdk v0.0.4/go.mod h1:KQZOtzcrXBlVhpZYG1tw83ADIONNMMPjUU3ZAH5U2RY=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=

View File

@@ -142,7 +142,7 @@ type TelegramInstantViewPage struct {
Content template.HTML Content template.HTML
Description string Description string
Subject string Subject string
Metadata *sdk.ProfileMetadata Metadata sdk.ProfileMetadata
AuthorLong string AuthorLong string
CreatedAt string CreatedAt string
ParentLink template.HTML ParentLink template.HTML
@@ -225,7 +225,7 @@ type NotePage struct {
Content template.HTML Content template.HTML
CreatedAt string CreatedAt string
Metadata *sdk.ProfileMetadata Metadata sdk.ProfileMetadata
Npub string Npub string
NpubShort string NpubShort string
ParentLink template.HTML ParentLink template.HTML
@@ -254,7 +254,7 @@ type ProfilePage struct {
CreatedAt string CreatedAt string
Domain string Domain string
LastNotes []EnhancedEvent LastNotes []EnhancedEvent
Metadata *sdk.ProfileMetadata Metadata sdk.ProfileMetadata
NormalizedAuthorWebsiteURL string NormalizedAuthorWebsiteURL string
RenderedAuthorAboutText template.HTML RenderedAuthorAboutText template.HTML
Nevent string Nevent string
@@ -283,7 +283,7 @@ type FileMetadataPage struct {
Content template.HTML Content template.HTML
CreatedAt string CreatedAt string
Metadata *sdk.ProfileMetadata Metadata sdk.ProfileMetadata
Npub string Npub string
NpubShort string NpubShort string
ParentLink template.HTML ParentLink template.HTML
@@ -316,7 +316,7 @@ type LiveEventPage struct {
Content template.HTML Content template.HTML
CreatedAt string CreatedAt string
Metadata *sdk.ProfileMetadata Metadata sdk.ProfileMetadata
Npub string Npub string
NpubShort string NpubShort string
ParentLink template.HTML ParentLink template.HTML
@@ -347,7 +347,7 @@ type LiveEventMessagePage struct {
Content template.HTML Content template.HTML
CreatedAt string CreatedAt string
Metadata *sdk.ProfileMetadata Metadata sdk.ProfileMetadata
Npub string Npub string
NpubShort string NpubShort string
ParentLink template.HTML ParentLink template.HTML
@@ -423,7 +423,7 @@ type RSSPage struct {
// for the profile RSS // for the profile RSS
Npub string Npub string
Metadata *sdk.ProfileMetadata Metadata sdk.ProfileMetadata
// for the relay RSS // for the relay RSS
RelayHostname string RelayHostname string