@@ -22,17 +22,13 @@ rewrite convert app req = do
2222-- 2) for a non-directory bar, check for bar.html
2323-- if the file exists, do the rewrite
2424autoHtmlRewrite :: String -> B.ByteString -> IO B.ByteString
25−autoHtmlRewrite staticDir pInfo =
26− let pieces = decodePathInfo $ B.unpack $ pInfo
27− in if null pieces then return pInfo
28− else
29− let fp = concat $ map ((:) '/') (reWritePieces pieces)
30− in do fe <- doesFileExist $ staticDir ++ "/" ++ fp
31− return $ if fe then B.pack fp else pInfo
32− where
33− reWritePieces :: [String] -> [String]
34− reWritePieces pieces =
35− let end = last pieces
36− in if null end
37− then pieces ++ ["index.html"]
38− else (init pieces) ++ [end ++ ".html"]
25+autoHtmlRewrite staticDir pInfo = do
26+ fe <- doesFileExist $ staticDir ++ "/" ++ reWritePath
27+ return $ if fe then B.pack reWritePath else pInfo
28+ where
29+ reWritePath = concat $ map ((:) '/') reWritePieces
30+ pieces = decodePathInfo $ B.unpack $ pInfo
31+ reWritePieces =
32+ if (null pieces) || (null $ last pieces)
33+ then pieces ++ ["index.html"]
34+ else (init pieces) ++ [(last pieces) ++ ".html"]