flounder

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

commit fd9aa385a5daab5f5a8f1f012fd2c57d622012c2
parent 79daa8d529197d67dfbc7d81cc57a9419a3a55d5
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Tue, 26 Jan 2021 20:54:14 -0800

make gemini url safe

Diffstat:
Mhttp.go | 8+++++++-
Mtemplates/user_page.html | 2+-
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/http.go b/http.go @@ -772,7 +772,13 @@ func checkDomainHandler(w http.ResponseWriter, r *http.Request) { func runHTTPServer() { log.Printf("Running http server with hostname %s on port %d.", c.Host, c.HttpPort) var err error - t = template.New("main").Funcs(template.FuncMap{"parent": path.Dir, "hasSuffix": strings.HasSuffix}) + t = template.New("main").Funcs(template.FuncMap{"parent": path.Dir, "hasSuffix": strings.HasSuffix, + "safeGeminiURL": func(u string) template.URL { + if strings.HasPrefix(u, "gemini://") { + return template.URL(u) + } + return "" + }}) t, err = t.ParseGlob(path.Join(c.TemplatesDirectory, "*.html")) if err != nil { log.Fatal(err) diff --git a/templates/user_page.html b/templates/user_page.html @@ -22,7 +22,7 @@ <br> {{ end }} <div class="footer"> - Proxied from the original at <a href="{{.URI.String}}">{{.URI.String}}</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="{{safeGeminiURL .URI.String}}">{{.URI.String}}</a> (<a href="https://admin.flounder.online/gemini.gmi">about Gemini</a>) <a href="?raw=1">raw</a></div> </main> </body> </html>