1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-28 11:44:51 +09:00

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 where
import Prelude import Prelude hiding (takeWhile)
import Data.Byteable (toBytes) import Data.Byteable (toBytes)
import Data.ByteString.Lazy (ByteString) import Data.ByteString.Lazy (ByteString)
import Data.Git.Storage (Git, getObject_) import Data.Git.Storage (Git, getObject_)
import Data.Git.Storage.Object (Object (..)) import Data.Git.Storage.Object (Object (..))
import Data.Git.Types (Blob (..), Tree (..)) 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 (decodeUtf8With)
import Data.Text.Encoding.Error (strictDecode) import Data.Text.Encoding.Error (strictDecode)
import System.FilePath (isExtSeparator)
import Vervis.Foundation (Widget) import Vervis.Foundation (Widget)
import Vervis.Render (renderSource) import Vervis.Render (renderSource)
@ -42,7 +43,8 @@ findReadme git tree = go $ treeGetEnts tree
go [] = return Nothing go [] = return Nothing
go ((_perm, name, ref) : es) = go ((_perm, name, ref) : es) =
let nameT = decodeUtf8With strictDecode $ toBytes name 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 then do
obj <- getObject_ git ref True obj <- getObject_ git ref True
case obj of case obj of