# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1523906331 -7200
# Node ID ec2984aa53dbffd161b432c8e0bb89dc97c3ecef
# Parent  c91c9b87929ec55ab6ae3faf445d4c426a1bb67d
mod_http_dir_listing2: Sort file listing such that directories come before files

diff -r c91c9b87929e -r ec2984aa53db mod_http_dir_listing2/mod_http_dir_listing2.lua
--- 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,