all repos — flounder @ 21ad7d7ab5855a1d32cf0b1b9cb5c96d0b40098e

A small site builder for the Gemini protocol

Improve navigation

Rename ./.. to the actual path
alex wennerberg alex@alexwennerberg.com
Thu, 07 Jan 2021 19:22:09 -0800
commit

21ad7d7ab5855a1d32cf0b1b9cb5c96d0b40098e

parent

73a19ea2ad46550ce1bc08b67a5fa8190fe50332

3 files changed, 21 insertions(+), 9 deletions(-)

jump to
M http.gohttp.go

@@ -13,6 +13,7 @@ "io"

"io/ioutil" "log" "net/http" + "net/url" "os" "path" "path/filepath"

@@ -536,6 +537,7 @@ return ""

} // 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 @@ htmlString = textToHTML(nil, gmi.ParseText(strings.NewReader(geminiContent)))

} 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 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) }
M proxy.goproxy.go

@@ -110,8 +110,8 @@ data := struct {

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 {
M templates/user_page.htmltemplates/user_page.html

@@ -11,11 +11,13 @@ <body>

<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>