From da3c29209fb9519913f5eb4fcc1b1a4986464f03 Mon Sep 17 00:00:00 2001 From: James Mills Date: Mon, 26 Jun 2017 01:48:07 -0700 Subject: Bump --- gopherproxy.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'gopherproxy.go') diff --git a/gopherproxy.go b/gopherproxy.go index 8c85448..fcce1ee 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -23,9 +23,16 @@ type tplRow struct { type Handler func(w http.ResponseWriter, req *http.Request) func renderDirectory(w http.ResponseWriter, tpl *template.Template, hostport string, d gopher.Directory) error { - out := make([]tplRow, len(d)) + var title string + + out := make([]tplRow, len(d.Items)) + + for i, x := range d.Items { + if x.Type == gopher.INFO && x.Selector == "TITLE" { + title = x.Description + continue + } - for i, x := range d { tr := tplRow{ Text: x.Description, Type: x.Type.String(), @@ -60,10 +67,14 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, hostport str out[i] = tr } + if title == "" { + title = hostport + } + return tpl.Execute(w, struct { Title string Lines []tplRow - }{hostport, out}) + }{title, out}) } // MakeGopherProxyHandler returns a Handler that proxies requests -- cgit v1.2.3-54-g00ecf