mirror of
https://github.com/aljazceru/njump.git
synced 2026-01-31 11:44:34 +01:00
Enable custom canonical via ENV
This commit is contained in:
8
main.go
8
main.go
@@ -15,7 +15,8 @@ import (
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
Port string `envconfig:"PORT" default:"2999"`
|
||||
Port string `envconfig:"PORT" default:"2999"`
|
||||
CanonicalHost string `envconfig:"CANONICAL_HOST" default:"njump.me"`
|
||||
}
|
||||
|
||||
//go:embed static/*
|
||||
@@ -25,11 +26,9 @@ var static embed.FS
|
||||
var templates embed.FS
|
||||
|
||||
var (
|
||||
s Settings
|
||||
|
||||
s Settings
|
||||
tmpl *template.Template
|
||||
templateMapping = make(map[string]string)
|
||||
|
||||
log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger()
|
||||
)
|
||||
|
||||
@@ -53,7 +52,6 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("couldn't process envconfig.")
|
||||
}
|
||||
|
||||
// initialize disk cache
|
||||
defer cache.initialize()()
|
||||
|
||||
|
||||
@@ -322,6 +322,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
||||
"lastNotes": renderableLastNotes,
|
||||
"parentNevent": parentNevent,
|
||||
"authorRelays": authorRelays,
|
||||
"CanonicalHost": s.CanonicalHost,
|
||||
}
|
||||
|
||||
// if a mapping is not found fallback to raw
|
||||
|
||||
@@ -62,6 +62,7 @@ func renderArchive(w http.ResponseWriter, r *http.Request) {
|
||||
"paginationUrl": area,
|
||||
"nextPage": fmt.Sprint(nextPage),
|
||||
"prevPage": fmt.Sprint(prevPage),
|
||||
"CanonicalHost": s.CanonicalHost,
|
||||
}
|
||||
|
||||
if len(data) != 0 {
|
||||
|
||||
@@ -64,12 +64,13 @@ func renderRelayPage(w http.ResponseWriter, r *http.Request) {
|
||||
"clients": []ClientReference{
|
||||
{Name: "Coracle", URL: "https://coracle.social/relays/" + hostname},
|
||||
},
|
||||
"type": "relay",
|
||||
"info": info,
|
||||
"hostname": hostname,
|
||||
"proxy": "https://" + hostname + "/njump/proxy?src=",
|
||||
"lastNotes": renderableLastNotes,
|
||||
"modifiedAt": lastEventAt.Format("2006-01-02T15:04:05Z07:00"),
|
||||
"type": "relay",
|
||||
"info": info,
|
||||
"hostname": hostname,
|
||||
"proxy": "https://" + hostname + "/njump/proxy?src=",
|
||||
"lastNotes": renderableLastNotes,
|
||||
"modifiedAt": lastEventAt.Format("2006-01-02T15:04:05Z07:00"),
|
||||
"CanonicalHost": s.CanonicalHost,
|
||||
}
|
||||
|
||||
if len(renderableLastNotes) != 0 {
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<meta name="twitter:description" content="{{.description | escapeString}}" />
|
||||
{{end}}
|
||||
|
||||
<link rel="canonical" href="https://nostr.com/{{.nevent | escapeString }}" />
|
||||
<link rel="canonical" href="https://{{.CanonicalHost}}/{{.nevent | escapeString }}" />
|
||||
|
||||
{{template "head_common.html" }}
|
||||
</head>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
{{end}}
|
||||
<meta property="twitter:card" content="summary" />
|
||||
|
||||
<link rel="canonical" href="https://nostr.com/{{.npub | escapeString }}" />
|
||||
<link rel="canonical" href="https://{{.CanonicalHost}}/{{.npub | escapeString }}" />
|
||||
<link
|
||||
rel="sitemap"
|
||||
type="application/xml"
|
||||
|
||||
Reference in New Issue
Block a user