mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-27 16:14:51 +09:00
Split readme detection to separate function
This commit is contained in:
parent
35354a18a7
commit
25bb1e5b83
1 changed files with 8 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue