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 = do
articles <- find (Article.at) $ articlesPath path
pages <- maybe (return Map.empty) (find (Page.at)) $ pagesPath path
articles <- find Article.at $ articlesPath path
pages <- maybe (return Map.empty) (find Page.at) $ pagesPath path
tags <- Map.fromList . filter (not . Set.null . snd)
<$> (Files.find (articlesPath path </> "tags") >>= mapM (articles `tagged`))
return (articles, pages, tags)

View file

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