From b080c32d4c6ad7c954d52dc17c82ac5ab3631e06 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Tue, 27 Aug 2019 16:47:45 +0200 Subject: [PATCH] =?UTF-8?q?Handle=20pages=20parameter=20:=20use=20custom?= =?UTF-8?q?=20value=20provided=20with=20the=20usual=20checks=20or=20defaul?= =?UTF-8?q?t=20it=20to=20=C2=ABpages/=C2=BB=20iif=20the=20directory=20exis?= =?UTF-8?q?ts,=20otherwise=20pages=20are=20deactivated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Blog/Path.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Blog/Path.hs b/src/Blog/Path.hs index f8ed96f..bac98c3 100644 --- a/src/Blog/Path.hs +++ b/src/Blog/Path.hs @@ -12,6 +12,7 @@ import Data.Aeson (ToJSON(..), (.=), pairs) import Data.Monoid ((<>)) import Files (File(..), filePath) import GHC.Generics (Generic) +import System.Directory (doesDirectoryExist) data Path = Path { articlesPath :: FilePath @@ -28,10 +29,16 @@ instance ToJSON Path where <> "pagesPath" .= pagesPath ) +getPagesPath :: Maybe FilePath -> IO (Maybe FilePath) +getPagesPath Nothing = do + checkPagesPath <- doesDirectoryExist "pages" + return $ if checkPagesPath then Just "pages" else Nothing +getPagesPath (Just p) = Just <$> (filePath $ Dir p) + build :: FilePath -> Arguments -> IO Path build root arguments = do articlesPath <- filePath . Dir $ Arguments.articlesPath arguments - pagesPath <- mapM (filePath . Dir) $ Arguments.pagesPath arguments + pagesPath <- getPagesPath $ Arguments.pagesPath arguments remarkableConfig <- mapM (filePath . File) $ Arguments.remarkableConfig arguments return $ Path { articlesPath, commentsAt, pagesPath, remarkableConfig, root