Diff

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
parent 3002:c91c9b87929e
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,