From 7257af2905500d59d317144ae3e8b91a16e65d52 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 27 Apr 2021 11:30:04 -0400 Subject: [PATCH 1/2] Strip HTTP port from Gopher links Previously, if running an instance on e.g. http://localhost:8080, the port would show up in the Gopher links and potentially cause rendering to fail. This fixes that. --- gopher.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gopher.go b/gopher.go index 56d3fd6..4173fb0 100644 --- a/gopher.go +++ b/gopher.go @@ -14,6 +14,7 @@ import ( "bytes" "fmt" "io" + "net/url" "regexp" "strings" @@ -31,7 +32,12 @@ func initGopher(apper Apper) { // Utility function to strip the URL from the hostname provided by app.cfg.App.Host func stripHostProtocol(app *App) string { - return string(regexp.MustCompile("^.*://").ReplaceAll([]byte(app.cfg.App.Host), []byte(""))) + u, err := url.Parse(app.cfg.App.Host) + if err != nil { + // Fall back to host, with scheme stripped + return string(regexp.MustCompile("^.*://").ReplaceAll([]byte(app.cfg.App.Host), []byte(""))) + } + return u.Hostname() } func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error { From 02bb5013a7aac32b4c05dce33c43456e76a3bc86 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 27 Apr 2021 11:39:28 -0400 Subject: [PATCH 2/2] Show blog title and description via Gopher --- gopher.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gopher.go b/gopher.go index 4173fb0..f87d85c 100644 --- a/gopher.go +++ b/gopher.go @@ -106,6 +106,11 @@ func handleGopherCollection(app *App, w gopher.ResponseWriter, r *gopher.Request } c.hostName = app.cfg.App.Host + w.WriteInfo(c.DisplayTitle()) + if c.Description != "" { + w.WriteInfo(c.Description) + } + posts, err := app.db.GetPosts(app.cfg, c, 0, false, false, false) if err != nil { return err