hablo/src/Blog/Path.hs

35 lines
1.0 KiB
Haskell

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module Blog.Path (
Path(..)
, build
) where
import Arguments (Arguments)
import qualified Arguments as Arguments (Arguments(..))
import Data.Aeson (ToJSON(..), (.=), pairs)
import Data.Monoid ((<>))
import Files (File(..), filePath)
import GHC.Generics (Generic)
data Path = Path {
articlesPath :: FilePath
, pagesPath :: Maybe FilePath
, remarkableConfig :: Maybe FilePath
, root :: FilePath
} deriving Generic
instance ToJSON Path where
toEncoding (Path {articlesPath, pagesPath}) = pairs (
"articlesPath" .= articlesPath
<> "pagesPath" .= pagesPath
)
build :: FilePath -> Arguments -> IO Path
build root arguments = do
articlesPath <- filePath . Dir $ Arguments.articlesPath arguments
pagesPath <- mapM (filePath . Dir) $ Arguments.pagesPath arguments
remarkableConfig <- mapM (filePath . File) $ Arguments.remarkableConfig arguments
return $ Path {articlesPath, pagesPath, remarkableConfig, root}