how meta. (fork of alex's darcsden) — http://darcsden.com/
Refactored getReadme and added an isTooLarge function for checking blob source.
import qualified Data.ByteString.Lazy as LBS
if LBS.length source > (1024 * 1024) -- 1 MiB
if isTooLarge source
import Data.Maybe (isJust)
import Data.Maybe (isJust, listToMaybe)
isTooLarge :: LBS.ByteString -> Bool
isTooLarge = (> (1024 * 1024)) . LBS.length
case tree of
case findReadmes tree of
Just t -> let readmes = map (fromAnchored . fst) $ filter (\(a, _) -> "README" `isPrefixOf` fromAnchored a) (T.list t)
in case readmes of
[] -> return Nothing
(r:_) -> do s <- getBlob dr (f ++ [r])
if ".markdown" `isSuffixOf` r || ".md" `isSuffixOf` r
then return $ fmap (writeHtmlString defaultWriterOptions . readMarkdown defaultParserState . fromLBS) s
else return $ fmap (flip (highlight r) [] . fromLBS) s
Just r -> do
s <- getBlob dr (f ++ [r])
case s of
Nothing -> return Nothing
Just big | isTooLarge big -> return (Just "README file too large. Sorry.")
Just md | isMarkdown r ->
return . Just . doMarkdown . fromLBS $ md
Just source ->
return . Just . flip (highlight r) [] . fromLBS $ source
where
findReadmes = maybe Nothing listToMaybe . fmap (filter isReadme . map (fromAnchored . fst) . T.list)
doMarkdown = writeHtmlString defaultWriterOptions . readMarkdown defaultParserState
isReadme s = "README" `isPrefixOf` s || "readme" `isPrefixOf` s
isMarkdown s = ".markdown" `isSuffixOf` s || ".md" `isSuffixOf` s