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:
parent
94e323d715
commit
b080c32d4c
1 changed files with 8 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue