diff options
| -rw-r--r-- | intercept.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/intercept.go b/intercept.go index eeea651..3be3ddf 100644 --- a/intercept.go +++ b/intercept.go @@ -85,8 +85,30 @@ func (t *TemplateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func execTemplate(w http.ResponseWriter, r *http.Request, data string) { - links := getToken(data) - sort.Sort(LinksAsSlice(links)) // see sort.go + // We get all links in the document + allLinks := getToken(data) + + // all directories + var dirs []Link + // all files + var links []Link + + // we split the file and directory links + for k, v := range allLinks { + if allLinks[k].IsDir { + dirs = append(dirs, v) + } else { + links = append(links, v) + } + } + // sort them independent + sort.Sort(LinksAsSlice(dirs)) + sort.Sort(LinksAsSlice(links)) + + // merge them back + allLinks = append(dirs, links...) + + // ... now directories are listed first tmpl := template.New("page") tmpl, err := tmpl.Parse(getTemplate()) @@ -102,7 +124,7 @@ func execTemplate(w http.ResponseWriter, r *http.Request, data string) { URL string Favicon template.HTML AllowUpload bool - }{Links: links, URL: r.URL.Path, Favicon: getFavicon(), AllowUpload: _allow_upload}) + }{Links: allLinks, URL: r.URL.Path, Favicon: getFavicon(), AllowUpload: _allow_upload}) if err != nil { log.Println(err) } |
