changeset 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 693d16c18e29
files mod_http_dir_listing2/mod_http_dir_listing2.lua
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_dir_listing2/mod_http_dir_listing2.lua	Mon Apr 16 21:18:47 2018 +0200
+++ b/mod_http_dir_listing2/mod_http_dir_listing2.lua	Mon Apr 16 21:18:51 2018 +0200
@@ -46,6 +46,13 @@
 			table.insert(filelist, { class = class, href = build_path(path), type = type, text = file });
 		end
 	end
+	table.sort(filelist, function (a, b)
+		if a.href == ".." then return true end
+		if b.href == ".." then return false end
+		if a.class:match"directory" and not b.class:match"directory" then return true end
+		if not a.class:match"directory" and b.class:match"directory" then return false end
+		return a.text < b.text;
+	end);
 	return render(dir_index_template, {
 		path = path,
 		style = style,