diff options
| author | horus_arch | 2016-09-09 12:25:41 +0200 |
|---|---|---|
| committer | horus_arch | 2016-09-09 12:25:41 +0200 |
| commit | 32685cc367b86c81df3f025f63261aa91ea3cd8c (patch) | |
| tree | 5d0dc693a297d0640fa47b20cf6ffcb1f6776de0 | |
| parent | e34ee8e9ff1ebda0ec6f32e2bf93a8fd3e2a003b (diff) | |
| download | uhttpd-cgo.tar.gz | |
Fix sorting.cgo
| -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) } |
