diff options
Diffstat (limited to 'internal/port/gopher.go')
-rw-r--r-- | internal/port/gopher.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/internal/port/gopher.go b/internal/port/gopher.go index d2283c6..cb5e60c 100644 --- a/internal/port/gopher.go +++ b/internal/port/gopher.go | |||
@@ -49,10 +49,14 @@ func trimLeftChars(s string, n int) string { | |||
49 | return s[:0] | 49 | return s[:0] |
50 | } | 50 | } |
51 | 51 | ||
52 | func urlToNav(url string) (items []GopherNavItem) { | 52 | func urlToGopherNav(url string) (items []GopherNavItem) { |
53 | partialURL := "/gopher" | 53 | partialURL := "/gopher" |
54 | parts := strings.Split(url, "/") | 54 | parts := strings.Split(url, "/") |
55 | 55 | ||
56 | if len(parts) != 0 && parts[len(parts)-1] == "" { | ||
57 | parts = parts[:len(parts)-1] | ||
58 | } | ||
59 | |||
56 | for i, part := range parts { | 60 | for i, part := range parts { |
57 | if i == 1 { | 61 | if i == 1 { |
58 | partialURL = partialURL + "/1" | 62 | partialURL = partialURL + "/1" |
@@ -151,7 +155,7 @@ func renderGopherDirectory(w http.ResponseWriter, tpl *template.Template, assetL | |||
151 | URL: fmt.Sprintf("%s/%s", hostport, uri), | 155 | URL: fmt.Sprintf("%s/%s", hostport, uri), |
152 | Assets: assetList, | 156 | Assets: assetList, |
153 | Lines: out, | 157 | Lines: out, |
154 | Nav: urlToNav(fmt.Sprintf("%s/%s", hostport, uri)), | 158 | Nav: urlToGopherNav(fmt.Sprintf("%s/%s", hostport, uri)), |
155 | }) | 159 | }) |
156 | } | 160 | } |
157 | 161 | ||
@@ -194,7 +198,7 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass | |||
194 | Lines: []GopherItem{{ | 198 | Lines: []GopherItem{{ |
195 | Text: fmt.Sprintf("Error: %s", err), | 199 | Text: fmt.Sprintf("Error: %s", err), |
196 | }}, | 200 | }}, |
197 | Nav: urlToNav(hostport), | 201 | Nav: urlToGopherNav(hostport), |
198 | IsPlain: true, | 202 | IsPlain: true, |
199 | }); e != nil { | 203 | }); e != nil { |
200 | log.Println("Template error: " + e.Error()) | 204 | log.Println("Template error: " + e.Error()) |
@@ -224,7 +228,7 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass | |||
224 | Lines: []GopherItem{{ | 228 | Lines: []GopherItem{{ |
225 | Text: fmt.Sprintf("Error: %s", err), | 229 | Text: fmt.Sprintf("Error: %s", err), |
226 | }}, | 230 | }}, |
227 | Nav: urlToNav(fmt.Sprintf("%s/%s", hostport, uri)), | 231 | Nav: urlToGopherNav(fmt.Sprintf("%s/%s", hostport, uri)), |
228 | IsPlain: true, | 232 | IsPlain: true, |
229 | }); e != nil { | 233 | }); e != nil { |
230 | log.Println("Template error: " + e.Error()) | 234 | log.Println("Template error: " + e.Error()) |
@@ -246,7 +250,7 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass | |||
246 | Lines: []GopherItem{{ | 250 | Lines: []GopherItem{{ |
247 | Text: buf.String(), | 251 | Text: buf.String(), |
248 | }}, | 252 | }}, |
249 | Nav: urlToNav(fmt.Sprintf("%s/%s", hostport, uri)), | 253 | Nav: urlToGopherNav(fmt.Sprintf("%s/%s", hostport, uri)), |
250 | IsPlain: true, | 254 | IsPlain: true, |
251 | }); err != nil { | 255 | }); err != nil { |
252 | log.Println("Template error: " + err.Error()) | 256 | log.Println("Template error: " + err.Error()) |
@@ -271,7 +275,7 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass | |||
271 | Lines: []GopherItem{{ | 275 | Lines: []GopherItem{{ |
272 | Text: fmt.Sprintf("Error: %s", err), | 276 | Text: fmt.Sprintf("Error: %s", err), |
273 | }}, | 277 | }}, |
274 | Nav: urlToNav(fmt.Sprintf("%s/%s", hostport, uri)), | 278 | Nav: urlToGopherNav(fmt.Sprintf("%s/%s", hostport, uri)), |
275 | IsPlain: false, | 279 | IsPlain: false, |
276 | }); e != nil { | 280 | }); e != nil { |
277 | log.Println("Template error: " + e.Error()) | 281 | log.Println("Template error: " + e.Error()) |