Handle pages parameter : use custom value provided with the usual checks or default it to «pages/» iif the directory exists, otherwise pages are deactivated

This commit is contained in:
Tissevert 2019-08-27 16:47:45 +02:00
parent 94e323d715
commit b080c32d4c

View file

@ -12,6 +12,7 @@ import Data.Aeson (ToJSON(..), (.=), pairs)
import Data.Monoid ((<>)) import Data.Monoid ((<>))
import Files (File(..), filePath) import Files (File(..), filePath)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import System.Directory (doesDirectoryExist)
data Path = Path { data Path = Path {
articlesPath :: FilePath articlesPath :: FilePath
@ -28,10 +29,16 @@ instance ToJSON Path where
<> "pagesPath" .= pagesPath <> "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 :: FilePath -> Arguments -> IO Path
build root arguments = do build root arguments = do
articlesPath <- filePath . Dir $ Arguments.articlesPath arguments 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 remarkableConfig <- mapM (filePath . File) $ Arguments.remarkableConfig arguments
return $ Path { return $ Path {
articlesPath, commentsAt, pagesPath, remarkableConfig, root articlesPath, commentsAt, pagesPath, remarkableConfig, root