Mercurial > prosody-modules
comparison mod_http_dir_listing2/mod_http_dir_listing2.lua @ 3003:ec2984aa53db
mod_http_dir_listing2: Sort file listing such that directories come before files
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 16 Apr 2018 21:18:51 +0200 |
parents | c91c9b87929e |
children |
comparison
equal
deleted
inserted
replaced
3002:c91c9b87929e | 3003:ec2984aa53db |
---|---|
44 local class = table.concat({ attr.mode or "unknown", file_ext, type and type:match"^[^/]+" }, " "); | 44 local class = table.concat({ attr.mode or "unknown", file_ext, type and type:match"^[^/]+" }, " "); |
45 path.is_directory = attr.mode == "directory"; | 45 path.is_directory = attr.mode == "directory"; |
46 table.insert(filelist, { class = class, href = build_path(path), type = type, text = file }); | 46 table.insert(filelist, { class = class, href = build_path(path), type = type, text = file }); |
47 end | 47 end |
48 end | 48 end |
49 table.sort(filelist, function (a, b) | |
50 if a.href == ".." then return true end | |
51 if b.href == ".." then return false end | |
52 if a.class:match"directory" and not b.class:match"directory" then return true end | |
53 if not a.class:match"directory" and b.class:match"directory" then return false end | |
54 return a.text < b.text; | |
55 end); | |
49 return render(dir_index_template, { | 56 return render(dir_index_template, { |
50 path = path, | 57 path = path, |
51 style = style, | 58 style = style, |
52 filelist = filelist, | 59 filelist = filelist, |
53 footer = "Prosody "..prosody.version, | 60 footer = "Prosody "..prosody.version, |