initial commit

This commit is contained in:
outfoxxed 2025-02-10 20:03:25 -08:00
commit a60daddd0c
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
11 changed files with 333 additions and 0 deletions

25
src/Config.hs Normal file
View file

@ -0,0 +1,25 @@
{-# LANGUAGE DeriveGeneric #-}
module Config (
loadConfig,
Config (serve, plausible),
Serve (port, baseUrl, templateDir),
Plausible (queryUrl, token, siteId),
) where
import GHC.Generics (Generic)
import Data.Aeson (FromJSON, eitherDecodeFileStrict)
data Config = Config { serve :: !Serve, plausible :: !Plausible } deriving (Generic)
data Serve = Serve { port :: !Int, baseUrl :: !String, templateDir :: !String } deriving (Generic)
data Plausible = Plausible { queryUrl :: !String, token :: !String, siteId :: !String } deriving (Generic)
instance FromJSON Config where
instance FromJSON Serve where
instance FromJSON Plausible where
loadConfig :: FilePath -> IO Config
loadConfig path = loadConfig' =<< eitherDecodeFileStrict path
where loadConfig' :: Either String Config -> IO Config
loadConfig' (Left err) = fail err
loadConfig' (Right config) = return config