-
Notifications
You must be signed in to change notification settings - Fork 22
/
pages.go
514 lines (423 loc) · 12.2 KB
/
pages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
//go:generate tmpl bind ./...
package main
import (
_ "embed"
"html/template"
"strings"
"github.com/nbd-wtf/go-nostr/nip11"
sdk "github.com/nbd-wtf/nostr-sdk"
"github.com/tylermmorton/tmpl"
)
type TemplateID int
const (
Note TemplateID = iota
Profile
LongForm
TelegramInstantView
FileMetadata
LiveEvent
LiveEventMessage
Other
)
var (
//go:embed templates/opengraph.html
tmplOpenGraph string
OpenGraphTemplate = tmpl.MustCompile(&OpenGraphPartial{})
)
//tmpl:bind head_common.html
type OpenGraphPartial struct {
SingleTitle string
// x (we will always render just the singletitle if we have that)
Superscript string
Subscript string
BigImage string
// x (we will always render just the bigimage if we have that)
Video string
VideoType string
Image string
ProxiedImage string
// this is the main text we should always have
Text string
}
func (*OpenGraphPartial) TemplateText() string { return tmplOpenGraph }
var (
//go:embed templates/head_common.html
tmplHeadCommon string
HeadCommonTemplate = tmpl.MustCompile(&HeadCommonPartial{})
)
//tmpl:bind head_common.html
type HeadCommonPartial struct {
IsProfile bool
TailwindDebugStuff template.HTML
NaddrNaked string
NeventNaked string
Oembed string
}
func (*HeadCommonPartial) TemplateText() string { return tmplHeadCommon }
var (
//go:embed templates/top.html
tmplTop string
TopTemplate = tmpl.MustCompile(&TopPartial{})
)
//tmpl:bind top.html
type TopPartial struct{}
func (*TopPartial) TemplateText() string { return tmplTop }
var (
//go:embed templates/details.html
tmplDetails string
DetailsTemplate = tmpl.MustCompile(&DetailsPartial{})
)
//tmpl:bind details.html
type DetailsPartial struct {
HideDetails bool
CreatedAt string
EventJSON template.HTML
Nevent string
Nprofile string
Npub string
SeenOn []string
Kind int
KindNIP string
KindDescription string
// kind-specific stuff
FileMetadata *Kind1063Metadata
LiveEvent *Kind30311Metadata
}
func (*DetailsPartial) TemplateText() string { return tmplDetails }
var (
//go:embed templates/clients.html
tmplClients string
ClientsTemplate = tmpl.MustCompile(&ClientsPartial{})
)
//tmpl:bind clients.html
type ClientsPartial struct {
Clients []ClientReference
}
func (*ClientsPartial) TemplateText() string { return tmplClients }
var (
//go:embed templates/footer.html
tmplFooter string
FooterTemplate = tmpl.MustCompile(&FooterPartial{})
)
//tmpl:bind footer.html
type FooterPartial struct{}
func (*FooterPartial) TemplateText() string { return tmplFooter }
var (
//go:embed templates/telegram_instant_view.html
tmplTelegramInstantView string
TelegramInstantViewTemplate = tmpl.MustCompile(&TelegramInstantViewPage{})
)
type TelegramInstantViewPage struct {
Video string
VideoType string
Image string
Summary template.HTML
Content template.HTML
Description string
Subject string
Metadata sdk.ProfileMetadata
AuthorLong string
CreatedAt string
ParentLink template.HTML
}
func (*TelegramInstantViewPage) TemplateText() string { return tmplTelegramInstantView }
var (
//go:embed templates/homepage.html
tmplHomePage string
HomePageTemplate = tmpl.MustCompile(&HomePage{})
)
type HomePage struct {
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
FooterPartial `tmpl:"footer"`
Host string
Npubs []string
LastNotes []string
}
func (*HomePage) TemplateText() string { return tmplHomePage }
var (
//go:embed templates/archive.html
tmplArchive string
ArchiveTemplate = tmpl.MustCompile(&ArchivePage{})
)
type ArchivePage struct {
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
FooterPartial `tmpl:"footer"`
Title string
PathPrefix string
Data []string
ModifiedAt string
PaginationUrl string
NextPage int
PrevPage int
}
func (*ArchivePage) TemplateText() string { return tmplArchive }
var (
//go:embed templates/other.html
tmplOther string
OtherTemplate = tmpl.MustCompile(&OtherPage{})
)
type OtherPage struct {
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
DetailsPartial `tmpl:"details"`
FooterPartial `tmpl:"footer"`
Kind int
KindDescription string
Alt string
}
func (*OtherPage) TemplateText() string { return tmplOther }
var (
//go:embed templates/note.html
tmplNote string
NoteTemplate = tmpl.MustCompile(&NotePage{})
)
type NotePage struct {
OpenGraphPartial `tmpl:"opengraph"`
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
DetailsPartial `tmpl:"details"`
ClientsPartial `tmpl:"clients"`
FooterPartial `tmpl:"footer"`
Content template.HTML
CreatedAt string
Metadata sdk.ProfileMetadata
Npub string
NpubShort string
ParentLink template.HTML
SeenOn []string
Subject string
TitleizedContent string
}
func (*NotePage) TemplateText() string { return tmplNote }
var (
//go:embed templates/embedded_note.html
tmplEmbeddedNote string
EmbeddedNoteTemplate = tmpl.MustCompile(&EmbeddedNotePage{})
)
type EmbeddedNotePage struct {
Content template.HTML
CreatedAt string
Metadata sdk.ProfileMetadata
Npub string
NpubShort string
SeenOn []string
Subject string
Url string
}
func (*EmbeddedNotePage) TemplateText() string { return tmplEmbeddedNote }
var (
//go:embed templates/profile.html
tmplProfile string
ProfileTemplate = tmpl.MustCompile(&ProfilePage{})
)
type ProfilePage struct {
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
DetailsPartial `tmpl:"details"`
ClientsPartial `tmpl:"clients"`
FooterPartial `tmpl:"footer"`
AuthorRelays []string
Content string
CreatedAt string
Domain string
LastNotes []EnhancedEvent
Metadata sdk.ProfileMetadata
NormalizedAuthorWebsiteURL string
RenderedAuthorAboutText template.HTML
Nevent string
Npub string
Nprofile string
IsReply string
Proxy string
Title string
}
func (*ProfilePage) TemplateText() string { return tmplProfile }
var (
//go:embed templates/embedded_profile.html
tmplEmbeddedProfile string
EmbeddedProfileTemplate = tmpl.MustCompile(&EmbeddedProfilePage{})
)
type EmbeddedProfilePage struct {
AuthorRelays []string
Content string
CreatedAt string
Domain string
Metadata sdk.ProfileMetadata
NormalizedAuthorWebsiteURL string
RenderedAuthorAboutText template.HTML
Nevent string
Npub string
Nprofile string
Proxy string
Title string
}
func (*EmbeddedProfilePage) TemplateText() string { return tmplEmbeddedProfile }
var (
//go:embed templates/file_metadata.html
tmplFileMetadata string
FileMetadataTemplate = tmpl.MustCompile(&FileMetadataPage{})
)
type FileMetadataPage struct {
OpenGraphPartial `tmpl:"opengraph"`
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
DetailsPartial `tmpl:"details"`
ClientsPartial `tmpl:"clients"`
FooterPartial `tmpl:"footer"`
Content template.HTML
CreatedAt string
Metadata sdk.ProfileMetadata
Npub string
NpubShort string
ParentLink template.HTML
SeenOn []string
Style Style
Subject string
TitleizedContent string
Alt string
FileMetadata Kind1063Metadata
IsImage bool
IsVideo bool
}
func (*FileMetadataPage) TemplateText() string { return tmplFileMetadata }
var (
//go:embed templates/live_event.html
tmplLiveEvent string
LiveEventTemplate = tmpl.MustCompile(&LiveEventPage{})
)
type LiveEventPage struct {
OpenGraphPartial `tmpl:"opengraph"`
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
DetailsPartial `tmpl:"details"`
ClientsPartial `tmpl:"clients"`
FooterPartial `tmpl:"footer"`
Content template.HTML
CreatedAt string
Metadata sdk.ProfileMetadata
Npub string
NpubShort string
ParentLink template.HTML
SeenOn []string
Style Style
Subject string
TitleizedContent string
Alt string
LiveEvent Kind30311Metadata
}
func (*LiveEventPage) TemplateText() string { return tmplLiveEvent }
var (
//go:embed templates/live_event_message.html
tmplLiveEventMessage string
LiveEventMessageTemplate = tmpl.MustCompile(&LiveEventMessagePage{})
)
type LiveEventMessagePage struct {
OpenGraphPartial `tmpl:"opengraph"`
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
DetailsPartial `tmpl:"details"`
ClientsPartial `tmpl:"clients"`
FooterPartial `tmpl:"footer"`
Content template.HTML
CreatedAt string
Metadata sdk.ProfileMetadata
Npub string
NpubShort string
ParentLink template.HTML
SeenOn []string
Style Style
Subject string
TitleizedContent string
Alt string
LiveEventMessage Kind1311Metadata
}
func (*LiveEventMessagePage) TemplateText() string { return tmplLiveEventMessage }
var (
//go:embed templates/relay.html
tmplRelay string
RelayTemplate = tmpl.MustCompile(&RelayPage{})
)
type RelayPage struct {
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
ClientsPartial `tmpl:"clients"`
FooterPartial `tmpl:"footer"`
Info *nip11.RelayInformationDocument
Hostname string
Proxy string
LastNotes []EnhancedEvent
ModifiedAt string
}
func (*RelayPage) TemplateText() string { return tmplRelay }
var (
//go:embed templates/sitemap.xml
tmplSitemap string
SitemapTemplate = tmpl.MustCompile(&SitemapPage{})
)
type SitemapPage struct {
Host string
ModifiedAt string
// for the profile sitemap
Npub string
// for the relay sitemap
RelayHostname string
Info *nip11.RelayInformationDocument
// for the profile and relay sitemaps
LastNotes []EnhancedEvent
// for the archive sitemap
PathPrefix string
Data []string
}
func (*SitemapPage) TemplateText() string { return tmplSitemap }
var (
//go:embed templates/rss.xml
tmplRSS string
RSSTemplate = tmpl.MustCompile(&RSSPage{})
)
type RSSPage struct {
Host string
ModifiedAt string
Title string
// for the profile RSS
Npub string
Metadata sdk.ProfileMetadata
// for the relay RSS
RelayHostname string
Info *nip11.RelayInformationDocument
// for the profile and relay RSSs
LastNotes []EnhancedEvent
// for the archive RSS
PathPrefix string
Data []string
}
func (*RSSPage) TemplateText() string { return tmplRSS }
var (
//go:embed templates/error.html
tmplError string
ErrorTemplate = tmpl.MustCompile(&ErrorPage{})
)
type ErrorPage struct {
HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"`
FooterPartial `tmpl:"footer"`
Message template.HTML
Errors string
}
func (e *ErrorPage) TemplateText() string {
if e.Message != "" {
return tmplError
}
switch {
case strings.Contains(e.Errors, "invalid checksum"):
e.Message = "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"):
e.Message = "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"):
e.Message = "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...)"
default:
e.Message = "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!"
}
return tmplError
}