Simplify inelegant code

This commit is contained in:
Tissevert 2020-05-30 12:57:52 +02:00
parent fc8e26a983
commit baa1d0ce09
2 changed files with 8 additions and 11 deletions

View file

@ -95,8 +95,8 @@ tagged collection path = do
discover :: Path -> IO (Collection Article, Collection Page, Collection (Set String)) discover :: Path -> IO (Collection Article, Collection Page, Collection (Set String))
discover path = do discover path = do
articles <- find (Article.at) $ articlesPath path articles <- find Article.at $ articlesPath path
pages <- maybe (return Map.empty) (find (Page.at)) $ pagesPath path pages <- maybe (return Map.empty) (find Page.at) $ pagesPath path
tags <- Map.fromList . filter (not . Set.null . snd) tags <- Map.fromList . filter (not . Set.null . snd)
<$> (Files.find (articlesPath path </> "tags") >>= mapM (articles `tagged`)) <$> (Files.find (articlesPath path </> "tags") >>= mapM (articles `tagged`))
return (articles, pages, tags) return (articles, pages, tags)

View file

@ -20,15 +20,12 @@ absoluteLink ('.':path) = path
absoluteLink path = "/" </> path absoluteLink path = "/" </> path
filePath :: File -> IO FilePath filePath :: File -> IO FilePath
filePath file = do filePath (File path) = do
let (thePath, test, errorMessage) = bool <- doesFileExist path
case file of if bool then return path else die $ path ++ ": no such file"
File path -> (path, doesFileExist, (++ ": no such file")) filePath (Dir path) = do
Dir path -> (path, doesDirectoryExist, (++ ": no such directory")) bool <- doesDirectoryExist path
bool <- test thePath if bool then return path else die $ path ++ ": no such directory"
if bool
then return thePath
else die $ errorMessage thePath
find :: FilePath -> IO [FilePath] find :: FilePath -> IO [FilePath]
find path = find path =