flounder

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

commit 8bda7b71d80f1a3ca6c25209c1a95f4d9fa29051
parent b018dfaaadf20d89645330d7acaf094d60779f69
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 22 Nov 2020 14:11:36 -0800

Add index.gmi to subfolders

Diffstat:
Mhttp.go | 12+++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/http.go b/http.go @@ -432,13 +432,19 @@ func getFavicon(user string) string { func userFile(w http.ResponseWriter, r *http.Request) { userName := filepath.Clean(strings.Split(r.Host, ".")[0]) // clean probably unnecessary p := filepath.Clean(r.URL.Path) - if p == "/" { - p = "index.gmi" + // chcek if is directory for index.gmi file + var isDir bool + fileName := path.Join(c.FilesDirectory, userName, p) + stat, _ := os.Stat(fileName) + if stat != nil { + isDir = stat.IsDir() + } + if p == "/" || isDir { + fileName = path.Join(fileName, "index.gmi") } else if strings.HasPrefix(p, "/.hidden") { renderError(w, "404: file not found", 404) return } - fileName := path.Join(c.FilesDirectory, userName, p) extension := path.Ext(fileName) if r.URL.Path == "/style.css" { http.ServeFile(w, r, path.Join(c.TemplatesDirectory, "static/style.css"))