2019-02-22 23:29:35 +01:00
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
2019-02-19 21:48:55 +01:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
2019-02-22 23:29:35 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2019-02-15 15:11:31 +01:00
|
|
|
module Blog.Path (
|
|
|
|
Path(..)
|
|
|
|
, build
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Arguments (Arguments)
|
|
|
|
import qualified Arguments as Arguments (Arguments(..))
|
2019-02-22 23:29:35 +01:00
|
|
|
import Data.Aeson (ToJSON(..), (.=), pairs)
|
2019-02-19 21:48:55 +01:00
|
|
|
import Files (File(..), absolute, filePath)
|
2019-02-22 23:29:35 +01:00
|
|
|
import GHC.Generics (Generic)
|
2019-02-15 15:11:31 +01:00
|
|
|
|
|
|
|
data Path = Path {
|
|
|
|
articlesPath :: FilePath
|
2019-02-16 08:13:14 +01:00
|
|
|
, commentsAt :: Maybe String
|
2019-02-15 15:11:31 +01:00
|
|
|
, pagesPath :: Maybe FilePath
|
2019-02-22 22:02:07 +01:00
|
|
|
, remarkableConfig :: Maybe FilePath
|
2019-02-15 15:11:31 +01:00
|
|
|
, root :: FilePath
|
2019-02-22 23:29:35 +01:00
|
|
|
} deriving Generic
|
|
|
|
|
|
|
|
instance ToJSON Path where
|
|
|
|
toEncoding (Path {articlesPath, commentsAt, pagesPath}) = pairs (
|
|
|
|
"articlesPath" .= articlesPath
|
|
|
|
<> "commentsAt" .= commentsAt
|
|
|
|
<> "pagesPath" .= pagesPath
|
|
|
|
)
|
2019-02-15 15:11:31 +01:00
|
|
|
|
2019-02-19 21:48:55 +01:00
|
|
|
build :: Arguments -> IO Path
|
|
|
|
build arguments = do
|
|
|
|
articlesPath <- filePath . Dir $ Arguments.articlesPath arguments
|
|
|
|
pagesPath <- mapM (filePath . Dir) $ Arguments.pagesPath arguments
|
2019-02-22 22:02:07 +01:00
|
|
|
remarkableConfig <- mapM (filePath . File) $ Arguments.remarkableConfig arguments
|
2019-02-19 21:48:55 +01:00
|
|
|
root <- absolute . Dir $ Arguments.sourceDir arguments
|
|
|
|
return $ Path {
|
2019-02-22 22:02:07 +01:00
|
|
|
articlesPath, commentsAt, pagesPath, remarkableConfig, root
|
2019-02-19 21:48:55 +01:00
|
|
|
}
|
2019-02-22 22:02:07 +01:00
|
|
|
where
|
|
|
|
commentsAt = Arguments.commentsAt arguments
|