From 4fdfe9af0f5f4c0680a8d4148a276cc300d6c041 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Sun, 17 Nov 2019 11:28:53 +0100 Subject: Created proper startpage, support gemini:// links in Gopher mode --- gopherproxy.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'gopherproxy.go') diff --git a/gopherproxy.go b/gopherproxy.go index a91e057..8c0bb89 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -96,10 +96,20 @@ func renderGopherDirectory(w http.ResponseWriter, tpl *template.Template, assetL continue } - if strings.HasPrefix(x.Selector, "URL:") { - tr.Link = template.URL(x.Selector[4:]) - } else if strings.HasPrefix(x.Selector, "/URL:") { - tr.Link = template.URL(x.Selector[5:]) + if strings.HasPrefix(x.Selector, "URL:") || strings.HasPrefix(x.Selector, "/URL:") { + link := strings.TrimPrefix(strings.TrimPrefix(x.Selector, "/"), "URL:") + if strings.HasPrefix(link, "gemini://") { + link = fmt.Sprintf( + "/gemini/%s", + strings.TrimPrefix(link, "gemini://"), + ) + } else if strings.HasPrefix(link, "gopher://") { + link = fmt.Sprintf( + "/gopher/%s", + strings.TrimPrefix(link, "gopher://"), + ) + } + tr.Link = template.URL(link) } else { var hostport string if x.Port == 70 { -- cgit v1.2.3-54-g00ecf