WIP adding folders
alex wennerberg alex@alexwennerberg.com
Fri, 13 Nov 2020 00:31:02 -0800
3 files changed,
27 insertions(+),
8 deletions(-)
M
main.go
→
main.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.html
→
templates/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>