module Dir (createDirListing) where import System.Directory import Response import Config -- XXX is_head? content_type? last_modified? -- XXX move elsewhere! -- perhaps it would be best to return a ResponseBody here and -- let the upper layers handle the rest? createDirListing :: String -> String -> IO (ResponseBody,String) createDirListing urlpath dir = do fs <- getDirectoryContents dir let l = htmlFiles [f | f <- fs, (head f) /= '.'] title = "Directory " ++ urlpath -- XXX html quoted! parent = "Parent Directory\n" s = sec title (parent ++ l) p = page title s return (HereItIs p, contentTypeHeader "text/html") -- XXX this should probably be elsewhere htmlFiles fs = unlines ([""]) where hs = map htmlFile fs htmlFile f = "
  • " ++ f' ++ "
  • " where f' = f -- XXX html quoted page title body = "\n" ++ title ++ "\n\n" ++ body ++ "\n\n" sec title body = "

    " ++ title ++ "

    \n" ++ body