move templ params struct definitions for each page directly to their pages.

This commit is contained in:
fiatjaf
2024-08-03 14:27:46 -03:00
parent 4011528058
commit b1e8d53a0d
14 changed files with 199 additions and 199 deletions

195
pages.go
View File

@@ -7,10 +7,8 @@ package main
import (
_ "embed"
"html/template"
"strings"
"github.com/a-h/templ"
"github.com/nbd-wtf/go-nostr/nip11"
sdk "github.com/nbd-wtf/nostr-sdk"
)
@@ -69,201 +67,8 @@ type HeadParams struct {
Oembed string
}
type TelegramInstantViewParams struct {
Video string
VideoType string
Image string
Summary template.HTML
Content template.HTML
Description string
Subject string
Metadata sdk.ProfileMetadata
AuthorLong string
CreatedAt string
ParentNevent string
}
type HomePageParams struct {
HeadParams
Npubs []string
LastNotes []string
}
type AboutParams struct {
HeadParams
}
type EmbeddedNoteParams struct {
Content template.HTML
CreatedAt string
Metadata sdk.ProfileMetadata
SeenOn []string
Subject string
Url string
}
type ProfilePageParams struct {
HeadParams
Details DetailsParams
AuthorRelays []string
Content string
CreatedAt string
Domain string
LastNotes []EnhancedEvent
Metadata sdk.ProfileMetadata
NormalizedAuthorWebsiteURL string
RenderedAuthorAboutText template.HTML
Nevent string
Nprofile string
Proxy string
Title string
Clients []ClientReference
}
type EmbeddedProfileParams struct {
AuthorRelays []string
Content string
CreatedAt string
Domain string
Metadata sdk.ProfileMetadata
NormalizedAuthorWebsiteURL string
RenderedAuthorAboutText template.HTML
Nevent string
Nprofile string
Proxy string
Title string
}
type RelayPageParams struct {
HeadParams
Info nip11.RelayInformationDocument
Hostname string
Proxy string
LastNotes []EnhancedEvent
ModifiedAt string
Clients []ClientReference
}
type ErrorPageParams struct {
HeadParams
Errors string
Message string
}
func (e *ErrorPageParams) MessageHTML() template.HTML {
if e.Message != "" {
return template.HTML(e.Message)
}
switch {
case strings.Contains(e.Errors, "invalid checksum"):
return "It looks like you entered an invalid event code.<br> Check if you copied it fully, a good idea is compare the first and the last characters."
case strings.Contains(e.Errors, "couldn't find this"):
return "Can't find the event in the relays. Try getting an `nevent1` code with relay hints."
case strings.Contains(e.Errors, "invalid bech32 string length"),
strings.Contains(e.Errors, "invalid separator"),
strings.Contains(e.Errors, "not part of charset"):
return "You have typed a wrong event code, we need a URL path that starts with /npub1, /nprofile1, /nevent1, /naddr1, or something like /name@domain.com (or maybe just /domain.com) or an event id as hex (like /aef8b32af...)"
case strings.Contains(e.Errors, "profile metadata not found"):
return "We couldn't find the metadata (name, picture etc) for the specified user. Please check back here in 6 hours."
default:
return "I can't give any suggestions to solve the problem.<br> Please tag <a href='/dtonon.com'>daniele</a> and <a href='/fiatjaf.com'>fiatjaf</a> and complain!"
}
}
type BaseEventPageParams struct {
Event EnhancedEvent
Style Style
Alt string
}
type NotePageParams struct {
BaseEventPageParams
OpenGraphParams
HeadParams
Details DetailsParams
Content template.HTML
Cover string
Subject string
TitleizedContent string
Clients []ClientReference
}
type FileMetadataPageParams struct {
BaseEventPageParams
OpenGraphParams
HeadParams
Details DetailsParams
Content template.HTML
FileMetadata Kind1063Metadata
IsImage bool
IsVideo bool
Clients []ClientReference
}
type LiveEventPageParams struct {
BaseEventPageParams
OpenGraphParams
HeadParams
Details DetailsParams
Content template.HTML
LiveEvent Kind30311Metadata
Clients []ClientReference
}
type LiveEventMessagePageParams struct {
BaseEventPageParams
OpenGraphParams
HeadParams
Details DetailsParams
Content template.HTML
TitleizedContent string
Clients []ClientReference
}
type CalendarPageParams struct {
BaseEventPageParams
OpenGraphParams
HeadParams
Details DetailsParams
TimeZone string
StartAtDate string
StartAtTime string
EndAtDate string
EndAtTime string
Content template.HTML
CalendarEvent Kind31922Or31923Metadata
Clients []ClientReference
}
type WikiPageParams struct {
BaseEventPageParams
OpenGraphParams
HeadParams
Details DetailsParams
PublishedAt string
Content string
WikiEvent Kind30818Metadata
Clients []ClientReference
}
type OtherPageParams struct {
BaseEventPageParams
HeadParams
Details DetailsParams
Kind int
KindDescription string
}