Enable custom canonical via ENV

This commit is contained in:
Daniele Tonon
2023-09-06 13:57:35 +02:00
parent 9b6c6cb1fb
commit a20dcee2e9
6 changed files with 14 additions and 13 deletions

View File

@@ -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()()

View File

@@ -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

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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>

View File

@@ -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"