flounder

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

commit b74ecaec8871cf7641c243b21a2f006f3c0d1968
parent 30103dd54397d530516bf19dc2d6ae1278fe42c8
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed, 18 Nov 2020 18:47:15 -0800

Fix rendering bug  with folders

Diffstat:
Mhttp.go | 2+-
Mmain.go | 10++++++----
Mtemplates/my_site.html | 2+-
3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/http.go b/http.go @@ -207,7 +207,7 @@ func mySiteHandler(w http.ResponseWriter, r *http.Request) { } // check auth userFolder := path.Join(c.FilesDirectory, authUser) - files, _ := getFiles(userFolder) + files, _ := getMyFilesRecursive(userFolder, authUser) data := struct { Host string PageTitle string diff --git a/main.go b/main.go @@ -29,6 +29,7 @@ type File struct { // also folders TimeAgo string IsText bool Children []*File + Host string } type User struct { @@ -119,7 +120,7 @@ func getIndexFiles() ([]*File, error) { // cache this function return result, nil } // todo clean up paths -func getFiles(p string) ([]*File, error) { +func getMyFilesRecursive(p string, creator string) ([]*File, error) { result := []*File{} files, err := ioutil.ReadDir(p) if err != nil { @@ -130,13 +131,14 @@ func getFiles(p string) ([]*File, error) { fullPath := path.Join(p, file.Name()) localPath := getLocalPath(fullPath) f := &File{ - Name: localPath, - // Creator: strings.Split(p, "/")[0], + Name: localPath, + Creator: creator, UpdatedTime: file.ModTime(), IsText: isText, + Host: c.Host, } if file.IsDir() { - f.Children, err = getFiles(path.Join(p, file.Name())) + f.Children, err = getMyFilesRecursive(path.Join(p, file.Name()), creator) } result = append(result, f) } diff --git a/templates/my_site.html b/templates/my_site.html @@ -27,7 +27,7 @@ </td> {{ else }} <td> - <a href="//authUser.domain/{{.Name}}"> + <a href="//{{.Creator}}.{{.Host}}/{{.Name}}"> {{ .Name }}</a> </td> <td>