Split readme detection to separate function

This commit is contained in:
fr33domlover 2016-04-14 00:15:27 +00:00
parent 35354a18a7
commit 25bb1e5b83

View file

@ -35,6 +35,13 @@ import System.FilePath (isExtSeparator)
import Vervis.Foundation (Widget)
import Vervis.Render (renderSource)
-- | Check if the given filename should be considered as README file. Assumes
-- a flat filename which doesn't contain a directory part.
isReadme :: Text -> Bool
isReadme file =
let basename = takeWhile (not . isExtSeparator) file
in toCaseFold "readme" == toCaseFold basename
-- | Find a README file in a directory. Return the filename and the file
-- content.
findReadme :: Git -> Tree -> IO (Maybe (Text, ByteString))
@ -43,8 +50,7 @@ findReadme git tree = go $ treeGetEnts tree
go [] = return Nothing
go ((_perm, name, ref) : es) =
let nameT = decodeUtf8With strictDecode $ toBytes name
base = takeWhile (not . isExtSeparator) nameT
in if toCaseFold "readme" == toCaseFold base
in if isReadme nameT
then do
obj <- getObject_ git ref True
case obj of