Software /
code /
prosody-modules
Changeset
1064:5db8debb4531
mod_http_dir_listing: Attach the MIME type to list items for use in CSS
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 14 Jun 2013 12:09:00 +0200 |
parents | 1063:b2a4679e7d20 |
children | 1065:3d04d9377a67 |
files | mod_http_dir_listing/http_dir_listing/mod_http_dir_listing.lua |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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