all repos — flounder @ 3b6a527b8800e325039859b533049eeff5b061c2

A small site builder for the Gemini protocol

WIP adding folders
alex wennerberg alex@alexwennerberg.com
Fri, 13 Nov 2020 00:31:02 -0800
commit

3b6a527b8800e325039859b533049eeff5b061c2

parent

95f5edc1b5d2f7286e51338727592a159aaa2ae0

3 files changed, 27 insertions(+), 8 deletions(-)

jump to
M http.gohttp.go

@@ -206,7 +206,8 @@ renderError(w, "403: Forbidden", 403)

return } // check auth - files, _ := getUserFiles(authUser) + userFolder := path.Join(c.FilesDirectory, authUser) + files, _ := getFiles(userFolder) data := struct { Host string PageTitle string
M main.gomain.go

@@ -22,12 +22,13 @@ )

var c Config // global var to hold static configuration -type File struct { +type File struct { // also folders Creator string Name string UpdatedTime time.Time TimeAgo string IsText bool + Children []*File } type User struct {

@@ -111,20 +112,24 @@ }

return result, nil } // todo clean up paths -func getUserFiles(user string) ([]*File, error) { +func getFiles(p string) ([]*File, error) { result := []*File{} - files, err := ioutil.ReadDir(path.Join(c.FilesDirectory, user)) + files, err := ioutil.ReadDir(p) if err != nil { return nil, err } for _, file := range files { isText := strings.HasPrefix(mime.TypeByExtension(path.Ext(file.Name())), "text") - result = append(result, &File{ - Name: file.Name(), - Creator: user, + f := &File{ + Name: file.Name(), + // Creator: strings.Split(p, "/")[0], UpdatedTime: file.ModTime(), IsText: isText, - }) + } + if file.IsDir() { + f.Children, err = getFiles(path.Join(p, f.Name)) + } + result = append(result, f) } return result, nil }
M templates/my_site.htmltemplates/my_site.html

@@ -12,6 +12,18 @@ <table>

{{ range .Files }} <tr> <div> + {{ if .Children }} + <td> + <details> + <summary> + {{.Name}}/ + </summary> + {{ range .Children }} + {{.Name}} + {{ end }} + </details> + </td> + {{ else }} <td> <a href="//{{$authUser}}.{{$domain}}/{{.Name}}"> {{ .Name }}</a>

@@ -30,6 +42,7 @@ onclick="return confirm('Are you sure you want to delete this file?');"

value="delete" /> </td> + {{ end }} </form> </div> </tr>