Skip to content

Commit

Permalink
display empty profiles when no event is found.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Oct 12, 2024
1 parent 45c1905 commit 2145303
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
22 changes: 19 additions & 3 deletions profile.templ
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ templ profileTemplate(params ProfilePageParams) {
<html class="theme--default text-lg font-light print:text-base sm:text-xl">
<meta charset="UTF-8"/>
<head>
<title>{ params.Metadata.Name } / { params.Metadata.DisplayName } is on Nostr</title>
if params.Metadata.Name != "" && params.Metadata.DisplayName != "" {
<title>
{ params.Metadata.Name }
if params.Metadata.Name != "" && params.Metadata.DisplayName != "" {
/
}
{ params.Metadata.DisplayName } is on Nostr
</title>
}
<meta
name="description"
content={ fmt.Sprintf("%s is %s's public key on Nostr", params.Metadata.Npub(), params.Metadata.ShortName()) }
Expand Down Expand Up @@ -93,7 +101,13 @@ templ profileTemplate(params ProfilePageParams) {
<div class="w-full flex-1 break-words print:w-full sm:w-1/2">
<header class="mb-6 hidden leading-5 sm:flex sm:items-center">
<h1 class="sm:max-w-full">
<div id="profile_name" class="text-2xl break-words">{ params.Metadata.Name }</div>
<div id="profile_name" class="text-2xl break-words">
if params.Metadata.Event == nil {
<span class="text-stone-200 font-bold">&lt;unnamed&gt;</span>
} else {
{ params.Metadata.Name }
}
</div>
if params.Metadata.Name != params.Metadata.DisplayName {
<div class="text-xl text-stone-400 break-words">
{ params.Metadata.DisplayName }
Expand Down Expand Up @@ -164,7 +178,9 @@ templ profileTemplate(params ProfilePageParams) {
}
</div>
}
@detailsTemplate(params.Details)
if params.Metadata.Event != nil {
@detailsTemplate(params.Details)
}
if len(params.LastNotes) != 0 {
<aside>
<div class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 sm:-ml-2.5 dark:bg-zinc-700"></div>
Expand Down
20 changes: 9 additions & 11 deletions render_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@ func renderProfile(ctx context.Context, r *http.Request, w http.ResponseWriter,
}

profile, err := sys.FetchProfileFromInput(ctx, code)
if err != nil || profile.Event == nil {
if err != nil {
log.Warn().Err(err).Str("code", code).Msg("event not found on render_profile")
w.Header().Set("Cache-Control", "max-age=60")
w.WriteHeader(http.StatusNotFound)

errMsg := "profile metadata not found"
if err != nil {
errMsg = err.Error()
}
errorTemplate(ErrorPageParams{Errors: errMsg}).Render(ctx, w)
errorTemplate(ErrorPageParams{Errors: err.Error()}).Render(ctx, w)
return
} else {
} else if profile.Event != nil {
internal.scheduleEventExpiration(profile.Event.ID)
}

createdAt := profile.Event.CreatedAt.Time().Format("2006-01-02T15:04:05Z07:00")
modifiedAt := profile.Event.CreatedAt.Time().Format("2006-01-02T15:04:05Z07:00")
var createdAt string
if profile.Event != nil {
createdAt = profile.Event.CreatedAt.Time().Format("2006-01-02T15:04:05Z07:00")
}

var lastNotes []EnhancedEvent
if !isEmbed {
Expand All @@ -53,7 +51,7 @@ func renderProfile(ctx context.Context, r *http.Request, w http.ResponseWriter,
w.Write([]byte(XML_HEADER))
err = SitemapTemplate.Render(w, &SitemapPage{
Host: s.Domain,
ModifiedAt: modifiedAt,
ModifiedAt: createdAt,
LastNotes: lastNotes,
})
} else if isRSS {
Expand All @@ -62,7 +60,7 @@ func renderProfile(ctx context.Context, r *http.Request, w http.ResponseWriter,
w.Write([]byte(XML_HEADER))
err = RSSTemplate.Render(w, &RSSPage{
Host: s.Domain,
ModifiedAt: modifiedAt,
ModifiedAt: createdAt,
Metadata: profile,
LastNotes: lastNotes,
})
Expand Down
4 changes: 4 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ func getUTCOffset(loc *time.Location) string {
}

func toJSONHTML(evt *nostr.Event) template.HTML {
if evt == nil {
return ""
}

tagsHTML := "["
for t, tag := range evt.Tags {
tagsHTML += "\n ["
Expand Down

0 comments on commit 2145303

Please sign in to comment.