Detect README based on file basename

This commit is contained in:
fr33domlover 2016-04-14 00:01:56 +00:00
parent 85319ddfdc
commit 35354a18a7

View file

@ -20,16 +20,17 @@ module Vervis.Readme
)
where
import Prelude
import Prelude hiding (takeWhile)
import Data.Byteable (toBytes)
import Data.ByteString.Lazy (ByteString)
import Data.Git.Storage (Git, getObject_)
import Data.Git.Storage.Object (Object (..))
import Data.Git.Types (Blob (..), Tree (..))
import Data.Text (Text, toCaseFold, isPrefixOf, unpack)
import Data.Text (Text, toCaseFold, takeWhile, unpack)
import Data.Text.Encoding (decodeUtf8With)
import Data.Text.Encoding.Error (strictDecode)
import System.FilePath (isExtSeparator)
import Vervis.Foundation (Widget)
import Vervis.Render (renderSource)
@ -42,7 +43,8 @@ findReadme git tree = go $ treeGetEnts tree
go [] = return Nothing
go ((_perm, name, ref) : es) =
let nameT = decodeUtf8With strictDecode $ toBytes name
in if toCaseFold "readme" `isPrefixOf` toCaseFold nameT
base = takeWhile (not . isExtSeparator) nameT
in if toCaseFold "readme" == toCaseFold base
then do
obj <- getObject_ git ref True
case obj of