Simplify inelegant code
This commit is contained in:
parent
fc8e26a983
commit
baa1d0ce09
2 changed files with 8 additions and 11 deletions
|
@ -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)
|
||||
|
|
15
src/Files.hs
15
src/Files.hs
|
@ -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 =
|
||||
|
|
Loading…
Reference in a new issue