From a20dcee2e9f19e0aa124a8a50dafe44462136830 Mon Sep 17 00:00:00 2001 From: Daniele Tonon Date: Wed, 6 Sep 2023 13:57:35 +0200 Subject: [PATCH] Enable custom canonical via ENV --- main.go | 8 +++----- render.go | 1 + render_archive.go | 1 + render_relay.go | 13 +++++++------ templates/note.html | 2 +- templates/profile.html | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 4177914..868bac9 100644 --- a/main.go +++ b/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()() diff --git a/render.go b/render.go index 8d61bf2..18444a6 100644 --- a/render.go +++ b/render.go @@ -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 diff --git a/render_archive.go b/render_archive.go index b1af551..455b4a1 100644 --- a/render_archive.go +++ b/render_archive.go @@ -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 { diff --git a/render_relay.go b/render_relay.go index 777d886..816b997 100644 --- a/render_relay.go +++ b/render_relay.go @@ -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 { diff --git a/templates/note.html b/templates/note.html index ff997a7..cdd9ba7 100644 --- a/templates/note.html +++ b/templates/note.html @@ -30,7 +30,7 @@ {{end}} - + {{template "head_common.html" }} diff --git a/templates/profile.html b/templates/profile.html index 426a702..d4c83c3 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -20,7 +20,7 @@ {{end}} - +