mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-18 06:44:22 +01:00
relay pages at /r/... and nip05 pages at /p/...
This commit is contained in:
28
render.go
28
render.go
@@ -31,7 +31,22 @@ func render(w http.ResponseWriter, r *http.Request) {
|
|||||||
if strings.HasPrefix(code, "e/") {
|
if strings.HasPrefix(code, "e/") {
|
||||||
code, _ = nip19.EncodeEvent(code[2:], []string{}, "")
|
code, _ = nip19.EncodeEvent(code[2:], []string{}, "")
|
||||||
} else if strings.HasPrefix(code, "p/") {
|
} else if strings.HasPrefix(code, "p/") {
|
||||||
|
if urlSuffixMatcher.MatchString(code) {
|
||||||
|
// it's a nip05
|
||||||
|
code = code[2:]
|
||||||
|
} else {
|
||||||
|
// it's a hex pubkey
|
||||||
code, _ = nip19.EncodePublicKey(code[2:])
|
code, _ = nip19.EncodePublicKey(code[2:])
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(code, "r/") {
|
||||||
|
hostname := code[2:]
|
||||||
|
if strings.HasPrefix(hostname, "wss:/") || strings.HasPrefix(hostname, "ws:/") {
|
||||||
|
hostname = trimProtocol(hostname)
|
||||||
|
http.Redirect(w, r, "/r/"+hostname, http.StatusFound)
|
||||||
|
} else {
|
||||||
|
renderRelayPage(w, r)
|
||||||
|
}
|
||||||
|
return
|
||||||
} else if strings.HasPrefix(code, "nostr:") {
|
} else if strings.HasPrefix(code, "nostr:") {
|
||||||
http.Redirect(w, r, "/"+code[6:], http.StatusFound)
|
http.Redirect(w, r, "/"+code[6:], http.StatusFound)
|
||||||
} else if strings.HasPrefix(code, "npub") && strings.HasSuffix(code, ".xml") {
|
} else if strings.HasPrefix(code, "npub") && strings.HasSuffix(code, ".xml") {
|
||||||
@@ -50,19 +65,6 @@ func render(w http.ResponseWriter, r *http.Request) {
|
|||||||
// code can be a nevent, nprofile, npub or nip05 identifier, in which case we try to fetch the associated event
|
// code can be a nevent, nprofile, npub or nip05 identifier, in which case we try to fetch the associated event
|
||||||
event, err := getEvent(r.Context(), code)
|
event, err := getEvent(r.Context(), code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// this will fail if code is a relay URL, in which case we will handle it differently
|
|
||||||
|
|
||||||
// If the protocol is present strip it and redirect
|
|
||||||
if strings.HasPrefix(code, "wss:/") || strings.HasPrefix(code, "ws:/") {
|
|
||||||
hostname := trimProtocol(code)
|
|
||||||
http.Redirect(w, r, "/"+hostname, http.StatusFound)
|
|
||||||
}
|
|
||||||
|
|
||||||
if urlMatcher.MatchString(code) {
|
|
||||||
renderRelayPage(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
http.Error(w, "error fetching event: "+err.Error(), 404)
|
http.Error(w, "error fetching event: "+err.Error(), 404)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func renderRelayPage(w http.ResponseWriter, r *http.Request) {
|
func renderRelayPage(w http.ResponseWriter, r *http.Request) {
|
||||||
code := r.URL.Path[1:]
|
code := r.URL.Path[1:]
|
||||||
hostname := code
|
hostname := code[2:]
|
||||||
typ := "relay"
|
typ := "relay"
|
||||||
if strings.HasSuffix(hostname, ".xml") {
|
if strings.HasSuffix(hostname, ".xml") {
|
||||||
hostname = code[:len(hostname)-4]
|
hostname = code[:len(hostname)-4]
|
||||||
|
|||||||
@@ -7,15 +7,25 @@
|
|||||||
<meta property="og:site_name" content="{{.npub | escapeString}}" />
|
<meta property="og:site_name" content="{{.npub | escapeString}}" />
|
||||||
{{ if .metadata.Picture }}
|
{{ if .metadata.Picture }}
|
||||||
<meta property="og:image" content="{{.metadata.Picture | escapeString}}" />
|
<meta property="og:image" content="{{.metadata.Picture | escapeString}}" />
|
||||||
<meta property="twitter:image" content="{{.proxy}}{{.metadata.Picture | escapeString}}" />
|
<meta
|
||||||
{{end}}
|
property="twitter:image"
|
||||||
{{ if .metadata.About }}
|
content="{{.proxy}}{{.metadata.Picture | escapeString}}"
|
||||||
<meta property="og:description" content="{{.metadata.About | escapeString}}" />
|
/>
|
||||||
|
{{end}} {{ if .metadata.About }}
|
||||||
|
<meta
|
||||||
|
property="og:description"
|
||||||
|
content="{{.metadata.About | escapeString}}"
|
||||||
|
/>
|
||||||
{{end}}
|
{{end}}
|
||||||
<meta property="twitter:card" content="summary" />
|
<meta property="twitter:card" content="summary" />
|
||||||
|
|
||||||
<link rel="canonical" href="https://nostr.com/{{.npub | escapeString }}" />
|
<link rel="canonical" href="https://nostr.com/{{.npub | escapeString }}" />
|
||||||
<link rel="sitemap" type="application/xml" title="Sitemap for {{.npub | escapeString}}" href="/{{.npub | escapeString}}.xml">
|
<link
|
||||||
|
rel="sitemap"
|
||||||
|
type="application/xml"
|
||||||
|
title="Sitemap for {{.npub | escapeString}}"
|
||||||
|
href="/{{.npub | escapeString}}.xml"
|
||||||
|
/>
|
||||||
|
|
||||||
{{template "head_common.html" }}
|
{{template "head_common.html" }}
|
||||||
</head>
|
</head>
|
||||||
@@ -77,13 +87,12 @@
|
|||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="label">Posting on these relays</div>
|
<div class="label">Posting on these relays</div>
|
||||||
{{if .authorRelays}}
|
{{if .authorRelays}} {{range $index, $element := .authorRelays}}
|
||||||
{{range $index, $element := .authorRelays}}
|
<a href="/r/{{$element | escapeString}}" class="button"
|
||||||
<a href="/{{$element | escapeString}}" class="button">{{$element}}</a>
|
>{{$element}}</a
|
||||||
{{end}}
|
>
|
||||||
{{else}}
|
{{end}} {{else}} No relays found, sorry! Try to reload to search
|
||||||
No relays found, sorry! Try to reload to search again.
|
again. {{end}}
|
||||||
{{end}}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field last_update">
|
<div class="field last_update">
|
||||||
|
|||||||
2
utils.go
2
utils.go
@@ -92,7 +92,7 @@ var kindNIPS = map[int]string{
|
|||||||
30078: "78",
|
30078: "78",
|
||||||
}
|
}
|
||||||
|
|
||||||
var urlMatcher = regexp.MustCompile(`^(wss?:\/\/)?[\w-_.]+\.[\w-_.]+(\/[\/\w]*)?$`)
|
var urlSuffixMatcher = regexp.MustCompile(`[\w-_.]+\.[\w-_.]+(\/[\/\w]*)?$`)
|
||||||
|
|
||||||
type ClientReference struct {
|
type ClientReference struct {
|
||||||
Name string
|
Name string
|
||||||
|
|||||||
Reference in New Issue
Block a user