flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit ce21fbbef51b224e3897cbcf2b4639a191c97e39
parent 521dc799fb2e4b2080eb37f44115a2f2c6536a18
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu,  7 Jan 2021 00:07:08 -0800

fix path issues for proxy server

Diffstat:
Mgmi2html.go | 5+++--
Mhttp.go | 6+++---
Mproxy.go | 3+--
Mtemplates/user_page.html | 2+-
4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gmi2html.go b/gmi2html.go @@ -9,7 +9,7 @@ import ( "git.sr.ht/~adnano/go-gemini" ) -func textToHTML(text gemini.Text) string { +func textToHTML(reqUrl *url.URL, text gemini.Text) string { var b strings.Builder var pre bool var list bool @@ -32,7 +32,8 @@ func textToHTML(text gemini.Text) string { if err != nil { continue } - if u.Scheme == "gemini" { + u = reqUrl.ResolveReference(u) + if u.Scheme == "gemini" || u.Scheme == "" { if strings.HasSuffix(u.Host, c.Host) { u.Scheme = "" urlstring = html.EscapeString(u.String()) diff --git a/http.go b/http.go @@ -586,14 +586,14 @@ func userFile(w http.ResponseWriter, r *http.Request) { var htmlString string if geminiContent == "" { file, _ := os.Open(fullPath) - htmlString = textToHTML(gmi.ParseText(file)) + htmlString = textToHTML(nil, gmi.ParseText(file)) defer file.Close() } else { - htmlString = textToHTML(gmi.ParseText(strings.NewReader(geminiContent))) + htmlString = textToHTML(nil, gmi.ParseText(strings.NewReader(geminiContent))) } favicon := getFavicon(userName) hostname := strings.Split(r.Host, ":")[0] - URI := hostname + r.URL.String() + URI := "gemini://" + hostname + r.URL.String() data := struct { SiteBody template.HTML Favicon string diff --git a/proxy.go b/proxy.go @@ -33,7 +33,6 @@ func proxyGemini(w http.ResponseWriter, r *http.Request) { Timeout: 60 * time.Second, InsecureSkipTrust: true, } - fmt.Println(req) if h := (url.URL{Host: req.Host}); h.Port() == "" { req.Host += ":1965" @@ -106,7 +105,7 @@ func proxyGemini(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "text/html") - htmlString := textToHTML(gemini.ParseText(resp.Body)) + htmlString := textToHTML(req.URL, gemini.ParseText(resp.Body)) data := struct { SiteBody template.HTML Favicon string diff --git a/templates/user_page.html b/templates/user_page.html @@ -12,7 +12,7 @@ {{.SiteBody}} <br> <div class="footer"> - Proxied from the original at <a href="gemini://{{.URI}}">gemini://{{.URI}}</a> (<a href="https://admin.flounder.online/gemini.gmi">about Gemini</a>) <a href="./?raw=1">raw</a></div> + Proxied from the original at <a href="{{.URI}}">{{.URI}}</a> (<a href="https://admin.flounder.online/gemini.gmi">about Gemini</a>) <a href="./?raw=1">raw</a></div> </main> </body> </html>