mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 22:34:25 +01:00
move templ params struct definitions for each page directly to their pages.
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
type AboutParams struct {
|
||||||
|
HeadParams
|
||||||
|
}
|
||||||
|
|
||||||
templ aboutTemplate(params AboutParams) {
|
templ aboutTemplate(params AboutParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html class="theme--default font-light">
|
<html class="theme--default font-light">
|
||||||
|
|||||||
@@ -4,10 +4,26 @@ import (
|
|||||||
_ "embed"
|
_ "embed"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
"html/template"
|
||||||
"github.com/nbd-wtf/go-nostr/nip19"
|
"github.com/nbd-wtf/go-nostr/nip19"
|
||||||
"github.com/nbd-wtf/go-nostr/nip52"
|
"github.com/nbd-wtf/go-nostr/nip52"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func formatParticipants(participants []nip52.Participant) string {
|
func formatParticipants(participants []nip52.Participant) string {
|
||||||
var list = make([]string, 0)
|
var list = make([]string, 0)
|
||||||
for _, p := range participants {
|
for _, p := range participants {
|
||||||
|
|||||||
32
error.templ
32
error.templ
@@ -1,5 +1,37 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"html/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
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!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
templ errorTemplate(params ErrorPageParams) {
|
templ errorTemplate(params ErrorPageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html class="theme--default text-lg font-light print:text-base sm:text-xl">
|
<html class="theme--default text-lg font-light print:text-base sm:text-xl">
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "html/template"
|
||||||
|
|
||||||
|
type FileMetadataPageParams struct {
|
||||||
|
BaseEventPageParams
|
||||||
|
OpenGraphParams
|
||||||
|
HeadParams
|
||||||
|
|
||||||
|
Details DetailsParams
|
||||||
|
Content template.HTML
|
||||||
|
|
||||||
|
FileMetadata Kind1063Metadata
|
||||||
|
IsImage bool
|
||||||
|
IsVideo bool
|
||||||
|
|
||||||
|
Clients []ClientReference
|
||||||
|
}
|
||||||
|
|
||||||
templ fileMetadataTemplate(params FileMetadataPageParams) {
|
templ fileMetadataTemplate(params FileMetadataPageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@eventPageTemplate(
|
@eventPageTemplate(
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
type HomePageParams struct {
|
||||||
|
HeadParams
|
||||||
|
|
||||||
|
Npubs []string
|
||||||
|
LastNotes []string
|
||||||
|
}
|
||||||
|
|
||||||
templ homepageTemplate(params HomePageParams) {
|
templ homepageTemplate(params HomePageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html class="theme--default font-light">
|
<html class="theme--default font-light">
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "html/template"
|
||||||
|
|
||||||
|
type LiveEventPageParams struct {
|
||||||
|
BaseEventPageParams
|
||||||
|
OpenGraphParams
|
||||||
|
HeadParams
|
||||||
|
|
||||||
|
Details DetailsParams
|
||||||
|
Content template.HTML
|
||||||
|
|
||||||
|
LiveEvent Kind30311Metadata
|
||||||
|
Clients []ClientReference
|
||||||
|
}
|
||||||
|
|
||||||
templ liveEventTemplate(params LiveEventPageParams) {
|
templ liveEventTemplate(params LiveEventPageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@eventPageTemplate(
|
@eventPageTemplate(
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "html/template"
|
||||||
|
|
||||||
|
type LiveEventMessagePageParams struct {
|
||||||
|
BaseEventPageParams
|
||||||
|
OpenGraphParams
|
||||||
|
HeadParams
|
||||||
|
|
||||||
|
Details DetailsParams
|
||||||
|
Content template.HTML
|
||||||
|
TitleizedContent string
|
||||||
|
|
||||||
|
Clients []ClientReference
|
||||||
|
}
|
||||||
|
|
||||||
templ liveEventMessageTemplate(params LiveEventMessagePageParams) {
|
templ liveEventMessageTemplate(params LiveEventMessagePageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@eventPageTemplate(
|
@eventPageTemplate(
|
||||||
|
|||||||
15
note.templ
15
note.templ
@@ -1,5 +1,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "html/template"
|
||||||
|
|
||||||
|
type NotePageParams struct {
|
||||||
|
BaseEventPageParams
|
||||||
|
OpenGraphParams
|
||||||
|
HeadParams
|
||||||
|
|
||||||
|
Details DetailsParams
|
||||||
|
Content template.HTML
|
||||||
|
Cover string
|
||||||
|
Subject string
|
||||||
|
TitleizedContent string
|
||||||
|
Clients []ClientReference
|
||||||
|
}
|
||||||
|
|
||||||
templ noteTemplate(params NotePageParams) {
|
templ noteTemplate(params NotePageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@eventPageTemplate(
|
@eventPageTemplate(
|
||||||
|
|||||||
@@ -2,6 +2,15 @@ package main
|
|||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
|
type OtherPageParams struct {
|
||||||
|
BaseEventPageParams
|
||||||
|
HeadParams
|
||||||
|
|
||||||
|
Details DetailsParams
|
||||||
|
Kind int
|
||||||
|
KindDescription string
|
||||||
|
}
|
||||||
|
|
||||||
templ otherTemplate(params OtherPageParams) {
|
templ otherTemplate(params OtherPageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html class="theme--default text-lg font-light print:text-base sm:text-xl">
|
<html class="theme--default text-lg font-light print:text-base sm:text-xl">
|
||||||
|
|||||||
195
pages.go
195
pages.go
@@ -7,10 +7,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"html/template"
|
"html/template"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/a-h/templ"
|
"github.com/a-h/templ"
|
||||||
"github.com/nbd-wtf/go-nostr/nip11"
|
|
||||||
sdk "github.com/nbd-wtf/nostr-sdk"
|
sdk "github.com/nbd-wtf/nostr-sdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -69,201 +67,8 @@ type HeadParams struct {
|
|||||||
Oembed string
|
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 {
|
type BaseEventPageParams struct {
|
||||||
Event EnhancedEvent
|
Event EnhancedEvent
|
||||||
Style Style
|
Style Style
|
||||||
Alt string
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,29 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
sdk "github.com/nbd-wtf/nostr-sdk"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
templ profileTemplate(params ProfilePageParams) {
|
templ profileTemplate(params ProfilePageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|||||||
13
relay.templ
13
relay.templ
@@ -1,5 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "github.com/nbd-wtf/go-nostr/nip11"
|
||||||
|
|
||||||
|
type RelayPageParams struct {
|
||||||
|
HeadParams
|
||||||
|
|
||||||
|
Info nip11.RelayInformationDocument
|
||||||
|
Hostname string
|
||||||
|
Proxy string
|
||||||
|
LastNotes []EnhancedEvent
|
||||||
|
ModifiedAt string
|
||||||
|
Clients []ClientReference
|
||||||
|
}
|
||||||
|
|
||||||
templ relayTemplate(params RelayPageParams) {
|
templ relayTemplate(params RelayPageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html class="theme--default text-lg font-light print:text-base sm:text-xl">
|
<html class="theme--default text-lg font-light print:text-base sm:text-xl">
|
||||||
|
|||||||
@@ -1,5 +1,25 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
|
||||||
|
"github.com/nbd-wtf/nostr-sdk"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
templ telegramInstantViewTemplate(params TelegramInstantViewParams) {
|
templ telegramInstantViewTemplate(params TelegramInstantViewParams) {
|
||||||
<meta charset="UTF-8"/>
|
<meta charset="UTF-8"/>
|
||||||
<!-- check https://nikstar.me/post/instant-view/ for more information on how this was set up -->
|
<!-- check https://nikstar.me/post/instant-view/ for more information on how this was set up -->
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
type WikiPageParams struct {
|
||||||
|
BaseEventPageParams
|
||||||
|
OpenGraphParams
|
||||||
|
HeadParams
|
||||||
|
Details DetailsParams
|
||||||
|
PublishedAt string
|
||||||
|
Content string
|
||||||
|
WikiEvent Kind30818Metadata
|
||||||
|
Clients []ClientReference
|
||||||
|
}
|
||||||
|
|
||||||
templ wikiEventTemplate(params WikiPageParams) {
|
templ wikiEventTemplate(params WikiPageParams) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@eventPageTemplate(
|
@eventPageTemplate(
|
||||||
"Wiki - " + params.WikiEvent.Title,
|
"Wiki - "+params.WikiEvent.Title,
|
||||||
params.OpenGraphParams,
|
params.OpenGraphParams,
|
||||||
params.HeadParams,
|
params.HeadParams,
|
||||||
params.Clients,
|
params.Clients,
|
||||||
@@ -11,9 +22,9 @@ templ wikiEventTemplate(params WikiPageParams) {
|
|||||||
params.Event,
|
params.Event,
|
||||||
) {
|
) {
|
||||||
<h1 class="flex text-2xl items-center">
|
<h1 class="flex text-2xl items-center">
|
||||||
<div class="inline-block px-2 mr-2 text-base bg-strongpink text-white rounded-md">Wiki <span class="text-base">></span></div> <div class="inline-block">{ params.WikiEvent.Title }</div>
|
<div class="inline-block px-2 mr-2 text-base bg-strongpink text-white rounded-md">Wiki <span class="text-base">></span></div>
|
||||||
|
<div class="inline-block">{ params.WikiEvent.Title }</div>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<!-- main content -->
|
<!-- main content -->
|
||||||
<div dir="auto" class="leading-5" itemprop="articleBody">
|
<div dir="auto" class="leading-5" itemprop="articleBody">
|
||||||
@templ.Raw(params.Content)
|
@templ.Raw(params.Content)
|
||||||
|
|||||||
Reference in New Issue
Block a user