use naked (no relay hints) nip19 codes for canonical URLs and move them to head_common.

This commit is contained in:
fiatjaf
2023-10-28 11:48:56 -03:00
parent 500c136948
commit 1c36a379fd
5 changed files with 39 additions and 21 deletions

View File

@@ -68,7 +68,9 @@ type Data struct {
npubShort string npubShort string
nprofile string nprofile string
nevent string nevent string
neventNaked string
naddr string naddr string
naddrNaked string
createdAt string createdAt string
modifiedAt string modifiedAt string
parentLink template.HTML parentLink template.HTML
@@ -104,7 +106,9 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
npub, _ := nip19.EncodePublicKey(event.PubKey) npub, _ := nip19.EncodePublicKey(event.PubKey)
nprofile := "" nprofile := ""
nevent, _ := nip19.EncodeEvent(event.ID, relaysForNip19, event.PubKey) nevent, _ := nip19.EncodeEvent(event.ID, relaysForNip19, event.PubKey)
neventNaked, _ := nip19.EncodeEvent(event.ID, nil, event.PubKey)
naddr := "" naddr := ""
naddrNaked := ""
createdAt := time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02 15:04:05") createdAt := time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02 15:04:05")
modifiedAt := time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02T15:04:05Z07:00") modifiedAt := time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02T15:04:05Z07:00")
@@ -173,6 +177,7 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
templateId = Other templateId = Other
if d := event.Tags.GetFirst([]string{"d", ""}); d != nil { if d := event.Tags.GetFirst([]string{"d", ""}); d != nil {
naddr, _ = nip19.EncodeEntity(event.PubKey, event.Kind, d.Value(), relaysForNip19) naddr, _ = nip19.EncodeEntity(event.PubKey, event.Kind, d.Value(), relaysForNip19)
naddrNaked, _ = nip19.EncodeEntity(event.PubKey, event.Kind, d.Value(), nil)
} }
} }
} }
@@ -236,7 +241,9 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
npubShort: npubShort, npubShort: npubShort,
nprofile: nprofile, nprofile: nprofile,
nevent: nevent, nevent: nevent,
neventNaked: neventNaked,
naddr: naddr, naddr: naddr,
naddrNaked: naddrNaked,
authorRelays: authorRelays, authorRelays: authorRelays,
createdAt: createdAt, createdAt: createdAt,
modifiedAt: modifiedAt, modifiedAt: modifiedAt,

View File

@@ -30,6 +30,8 @@ var (
type HeadCommonPartial struct { type HeadCommonPartial struct {
IsProfile bool IsProfile bool
TailwindDebugStuff template.HTML TailwindDebugStuff template.HTML
NaddrNaked string
NeventNaked string
} }
func (*HeadCommonPartial) TemplateText() string { return tmplHeadCommon } func (*HeadCommonPartial) TemplateText() string { return tmplHeadCommon }
@@ -164,10 +166,9 @@ type OtherPage struct {
DetailsPartial `tmpl:"details"` DetailsPartial `tmpl:"details"`
FooterPartial `tmpl:"footer"` FooterPartial `tmpl:"footer"`
IsParameterizedReplaceable bool Naddr string
Naddr string Kind int
Kind int KindDescription string
KindDescription string
} }
func (*OtherPage) TemplateText() string { return tmplOther } func (*OtherPage) TemplateText() string { return tmplOther }
@@ -191,7 +192,6 @@ type NotePage struct {
Description string Description string
Image string Image string
Metadata nostr.ProfileMetadata Metadata nostr.ProfileMetadata
Nevent string
Npub string Npub string
NpubShort string NpubShort string
Oembed string Oembed string

View File

@@ -243,8 +243,13 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
}) })
case Note: case Note:
err = NoteTemplate.Render(w, &NotePage{ err = NoteTemplate.Render(w, &NotePage{
HeadCommonPartial: HeadCommonPartial{IsProfile: false, TailwindDebugStuff: tailwindDebugStuff}, HeadCommonPartial: HeadCommonPartial{
DetailsPartial: detailsData, IsProfile: false,
TailwindDebugStuff: tailwindDebugStuff,
NaddrNaked: data.naddrNaked,
NeventNaked: data.neventNaked,
},
DetailsPartial: detailsData,
ClientsPartial: ClientsPartial{ ClientsPartial: ClientsPartial{
Clients: generateClientList(code, data.event), Clients: generateClientList(code, data.event),
}, },
@@ -255,7 +260,6 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
Description: description, Description: description,
Image: data.image, Image: data.image,
Metadata: data.metadata, Metadata: data.metadata,
Nevent: data.nevent,
Npub: data.npub, Npub: data.npub,
NpubShort: data.npubShort, NpubShort: data.npubShort,
Oembed: oembed, Oembed: oembed,
@@ -272,12 +276,16 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
}) })
case Other: case Other:
err = OtherTemplate.Render(w, &OtherPage{ err = OtherTemplate.Render(w, &OtherPage{
HeadCommonPartial: HeadCommonPartial{IsProfile: false, TailwindDebugStuff: tailwindDebugStuff}, HeadCommonPartial: HeadCommonPartial{
DetailsPartial: detailsData, IsProfile: false,
IsParameterizedReplaceable: data.event.Kind >= 30000 && data.event.Kind < 40000, TailwindDebugStuff: tailwindDebugStuff,
Naddr: data.naddr, NaddrNaked: data.naddrNaked,
Kind: data.event.Kind, NeventNaked: data.neventNaked,
KindDescription: data.kindDescription, },
DetailsPartial: detailsData,
Naddr: data.naddr,
Kind: data.event.Kind,
KindDescription: data.kindDescription,
}) })
} }

View File

@@ -36,8 +36,6 @@
sizes="16x16" sizes="16x16"
href="/njump/static/favicon/event/favicon-16x16.png?v=2" href="/njump/static/favicon/event/favicon-16x16.png?v=2"
/> />
{{end}}
<meta name="theme-color" content="#e42a6d" />
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script> <script src="https://unpkg.com/hyperscript.org@0.9.12"></script>
{{ if not (eq "" .TailwindDebugStuff) }} {{ .TailwindDebugStuff }} {{ else }} {{ if not (eq "" .TailwindDebugStuff) }} {{ .TailwindDebugStuff }} {{ else }}
<link <link
@@ -53,7 +51,14 @@
} }
} }
</style> </style>
<meta name="theme-color" content="#e42a6d" />
{{ if eq "" .NaddrNaked }}
<link rel="canonical" href="https://njump.me/{{.NaddrNaked}}" />
{{ else }}
<link rel="canonical" href="https://njump.me/{{.NeventNaked}}" />
{{ end }}
<!---->
{{ end }}
<script type="text/hyperscript"> <script type="text/hyperscript">
on load get [navigator.userAgent.includes('Safari'), navigator.userAgent.includes('Chrome')] then if it[0] is true and it[1] is false add .safari to <body /> end on load get [navigator.userAgent.includes('Safari'), navigator.userAgent.includes('Chrome')] then if it[0] is true and it[1] is false add .safari to <body /> end
</script> </script>

View File

@@ -1,9 +1,8 @@
<!DOCTYPE html> <!doctype html>
<html class="theme--default text-lg sm:text-xl font-light print:text-base"> <html class="theme--default text-lg font-light print:text-base sm:text-xl">
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<head> <head>
<title>{{.TitleizedContent}}</title> <title>{{.TitleizedContent}}</title>
<title>{{.Nevent}} by {{.Metadata.Name}} is this note nostr ”nevent"</title>
<meta property="og:title" content="{{.Title}}" /> <meta property="og:title" content="{{.Title}}" />
{{ if eq .Style "twitter" }} {{ if eq .Style "twitter" }}
@@ -33,7 +32,6 @@
<meta name="twitter:description" content="{{.Description}}" /> <meta name="twitter:description" content="{{.Description}}" />
{{ end }} {{ end }}
<link rel="canonical" href="https://njump.me/{{.Nevent }}" />
<!----> <!---->
{{ if not (eq "" .Oembed) }} {{ if not (eq "" .Oembed) }}
<link <link