# HG changeset patch # User Kim Alvefur # Date 1371204540 -7200 # Node ID 5db8debb4531c0ed8656c5668d2aa56f0817ee9e # Parent b2a4679e7d20486489bd12e388ff072339150bee mod_http_dir_listing: Attach the MIME type to list items for use in CSS diff -r b2a4679e7d20 -r 5db8debb4531 mod_http_dir_listing/http_dir_listing/mod_http_dir_listing.lua --- a/mod_http_dir_listing/http_dir_listing/mod_http_dir_listing.lua Thu Jun 13 21:27:41 2013 +0200 +++ b/mod_http_dir_listing/http_dir_listing/mod_http_dir_listing.lua Fri Jun 14 12:09:00 2013 +0200 @@ -14,6 +14,10 @@ local tag = require"util.stanza".stanza; local template = require"util.template"; +module:depends"http_files"; + +local mime = module:shared("/*/http_files/mime"); + local function get_resource(resource) local fh = assert(module:load_resource(resource)); local data = fh:read"*a"; @@ -33,13 +37,17 @@ filelist:tag("li", { class = "parent directory" }) :tag("a", { href = "..", rel = "up" }):text("Parent Directory"):up():up():text"\n" end + local mime_map = mime.types; for file in lfs.dir(full_path) do if file:sub(1,1) ~= "." then local attr = stat(full_path..file) or {}; local path = { file }; + local file_ext = file:match"%.(.-)$"; + local type = attr.mode == "file" and mime_map and mime_map[file_ext] or nil; + local class = table.concat({ attr.mode or "unknown", file_ext, type and type:match"^[^/]+" }, " "); path.is_directory = attr.mode == "directory"; - filelist:tag("li", { class = attr.mode }) - :tag("a", { href = build_path(path) }):text(file):up() + filelist:tag("li", { class = class }) + :tag("a", { href = build_path(path), type = type }):text(file):up() :up():text"\n"; end end