flounder

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

commit 21ad7d7ab5855a1d32cf0b1b9cb5c96d0b40098e
parent 73a19ea2ad46550ce1bc08b67a5fa8190fe50332
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu,  7 Jan 2021 19:22:09 -0800

Improve navigation

Rename ./.. to the actual path

Diffstat:
Mhttp.go | 20+++++++++++++++-----
Mproxy.go | 4++--
Mtemplates/user_page.html | 6++++--
3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/http.go b/http.go @@ -13,6 +13,7 @@ import ( "io/ioutil" "log" "net/http" + "net/url" "os" "path" "path/filepath" @@ -536,6 +537,7 @@ func getFavicon(user string) string { } // Server a user's file +// TODO replace with gemini proxy // Here be dragons func userFile(w http.ResponseWriter, r *http.Request) { userName := filepath.Clean(strings.Split(r.Host, ".")[0]) // Clean probably unnecessary @@ -594,14 +596,21 @@ func userFile(w http.ResponseWriter, r *http.Request) { } favicon := getFavicon(userName) hostname := strings.Split(r.Host, ":")[0] - URI := "gemini://" + hostname + r.URL.String() + uri := url.URL{ + Scheme: "gemini", + Host: hostname, + Path: p, + } data := struct { SiteBody template.HTML Favicon string PageTitle string - URI string - }{template.HTML(htmlString), favicon, userName + p, URI} - t.ExecuteTemplate(w, "user_page.html", data) + URI *url.URL + }{template.HTML(htmlString), favicon, userName + p, &uri} + err = t.ExecuteTemplate(w, "user_page.html", data) + if err != nil { + panic(err) + } } else { http.ServeFile(w, r, fullPath) } @@ -715,7 +724,8 @@ func adminUserHandler(w http.ResponseWriter, r *http.Request) { func runHTTPServer() { log.Printf("Running http server with hostname %s on port %d. TLS enabled: %t", c.Host, c.HttpPort, c.HttpsEnabled) var err error - t, err = template.ParseGlob(path.Join(c.TemplatesDirectory, "*.html")) + t = template.New("main").Funcs(template.FuncMap{"parent": path.Dir}) + t, err = t.ParseGlob(path.Join(c.TemplatesDirectory, "*.html")) if err != nil { log.Fatal(err) } diff --git a/proxy.go b/proxy.go @@ -110,8 +110,8 @@ func proxyGemini(w http.ResponseWriter, r *http.Request) { SiteBody template.HTML Favicon string PageTitle string - URI string - }{template.HTML(htmlString), "", req.URL.String(), req.URL.String()} + URI *url.URL + }{template.HTML(htmlString), "", req.URL.String(), req.URL} err = t.ExecuteTemplate(w, "user_page.html", data) if err != nil { diff --git a/templates/user_page.html b/templates/user_page.html @@ -11,11 +11,13 @@ <main> {{.SiteBody}} <br> -<a href=".." title="Go to the parent directory">./..</a> +{{ if ne .URI.Path "/"}} +<a href=".." title="Go to the parent directory">{{parent .URI.Path}}</a> +{{ end }} <br> <br> <div class="footer"> - 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> + 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> </main> </body> </html>