comparison mod_http_dir_listing/http_dir_listing/mod_http_dir_listing.lua @ 1099:754c15641369

mod_http_dir_listing: Fix file ending detection for filenames with more than one period and don't index mime types with nil
author Kim Alvefur <zash@zash.se>
date Mon, 01 Jul 2013 23:06:00 +0200
parents cb21928bca1d
children 7dbde05b48a9
comparison
equal deleted inserted replaced
1098:cbbeac61f1ab 1099:754c15641369
38 local mime_map = mime.types; 38 local mime_map = mime.types;
39 for file in lfs.dir(full_path) do 39 for file in lfs.dir(full_path) do
40 if file:sub(1,1) ~= "." then 40 if file:sub(1,1) ~= "." then
41 local attr = stat(full_path..file) or {}; 41 local attr = stat(full_path..file) or {};
42 local path = { file }; 42 local path = { file };
43 local file_ext = file:match"%.(.-)$"; 43 local file_ext = file:match"%.([^.]+)$";
44 local type = attr.mode == "file" and mime_map and mime_map[file_ext] or nil; 44 local type = attr.mode == "file" and file_ext and mime_map and mime_map[file_ext] or nil;
45 local class = table.concat({ attr.mode or "unknown", file_ext, type and type:match"^[^/]+" }, " "); 45 local class = table.concat({ attr.mode or "unknown", file_ext, type and type:match"^[^/]+" }, " ");
46 path.is_directory = attr.mode == "directory"; 46 path.is_directory = attr.mode == "directory";
47 filelist:tag("li", { class = class }) 47 filelist:tag("li", { class = class })
48 :tag("a", { href = build_path(path), type = type }):text(file):up() 48 :tag("a", { href = build_path(path), type = type }):text(file):up()
49 :up():text"\n"; 49 :up():text"\n";