From 25bb1e5b8389a2d8e32cd80a9acbb9b8dcd0edcd Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Thu, 14 Apr 2016 00:15:27 +0000 Subject: [PATCH] Split readme detection to separate function --- src/Vervis/Readme.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Vervis/Readme.hs b/src/Vervis/Readme.hs index 22e61d4..00402a7 100644 --- a/src/Vervis/Readme.hs +++ b/src/Vervis/Readme.hs @@ -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