🐙 Templated web page generator for your git repositories
git clone https://github.com/m-col/gitja
Files | Refs | Readme | License

Commit d8a16891b85e1bcf43e78c426aab5f937a4311a8
Parent: a6efc95f7783b76592e97d1c9c2d7206ccf3617b
Author: mcol <mcol@posteo.net>
Date: 2021-12-04 00:09:26 +0300
Committer: mcol <mcol@posteo.net>
Committed: 2021-12-04 00:09:26 +0300

Add conf prefix to config options in the code

src/Templates.hs Modified

@@ -78,20 +78,20 @@
 loadEnv :: Bool -> Bool -> Config -> IO Env
 loadEnv quiet force config = do
     -- First ensure that the output directory exists
-    output <- parseAbsDir <=< canonicalizePath . outputDirectory $ config
+    output <- parseAbsDir <=< canonicalizePath . confOutputDirectory $ config
     ensureDir output
 
     -- Parse repos for env
-    repoPaths' <-
-        if scanRepoPaths config
+    repoPaths <-
+        if confScanRepoPaths config
             then do
-                ps <- fmap concat . mapM (fmap fst . ls) . repoPaths $ config
+                ps <- fmap concat . mapM (fmap fst . ls) . confRepoPaths $ config
                 return . filter ((/=) ".git" . toFilePath . dirname) $ ps
-            else mapM (parseAbsDir <=< canonicalizePath) . repoPaths $ config
+            else mapM (parseAbsDir <=< canonicalizePath) . confRepoPaths $ config
 
     -- Find template files, copying the static files as is
-    (dirs, files) <- ls . templateDirectory $ config
-    (_, filesRepo) <- ls $ templateDirectory config FP.</> "repo"
+    (dirs, files) <- ls . confTemplateDirectory $ config
+    (_, filesRepo) <- ls $ confTemplateDirectory config FP.</> "repo"
     copyStaticDirs output dirs
     copyStaticFiles output files
 
@@ -113,8 +113,8 @@
             , envFileTemplate = fileT
             , envRepoTemplates = repoT
             , envOutputDirectory = output
-            , envRepoPaths = repoPaths'
-            , envHost = host config
+            , envRepoPaths = repoPaths
+            , envHost = confHost config
             , envQuiet = quiet
             , envForce = force
             }
@@ -187,13 +187,13 @@
 
 {-
 The logic for copying static files and folders. Any file or folder in the
-``templateDirectory`` is considered static if:
+``confTemplateDirectory`` is considered static if:
 
 - it is a symbolic link, or
 - it does not end in ".html" or ".include".
 
 Symbolic links are not followed and are copied as is. This means that a symbolic link
-from `templateDirectory/link.html` to `gitserve/index.html` will be copied, keeping the
+from `confTemplateDirectory/link.html` to `gitserve/index.html` will be copied, keeping the
 link intact, resulting in a symbolic link at `outputDirectory/link.html` essentially
 pointing to `outputDirectory/gitserve/index.html`.
 -}

src/Config.hs Modified

@@ -1,6 +1,8 @@
 -- Required by Dhall
+{-# LANGUAGE DataKinds #-}
 {-# LANGUAGE DeriveGeneric #-}
-{-# LANGUAGE DerivingStrategies #-}
+{-# LANGUAGE DerivingVia #-}
+{-# LANGUAGE TypeOperators #-}
 
 module Config (
     Config (..),
@@ -10,18 +12,20 @@
 import Control.Monad ((<=<))
 import Data.Text (pack)
 import Dhall
+import Dhall.Deriving
 import System.Directory (makeAbsolute)
 
 data Config = Config
-    { repoPaths :: [FilePath]
-    , scanRepoPaths :: Bool
-    , templateDirectory :: FilePath
-    , outputDirectory :: FilePath
-    , host :: Text
+    { confRepoPaths :: [FilePath]
+    , confScanRepoPaths :: Bool
+    , confTemplateDirectory :: FilePath
+    , confOutputDirectory :: FilePath
+    , confHost :: Text
     }
-    deriving stock (Generic, Show)
-
-instance FromDhall Config
+    deriving stock (Generic)
+    deriving
+        (FromDhall)
+        via Codec (Field (CamelCase <<< DropPrefix "conf")) Config
 
 getConfig :: String -> IO Config
 getConfig = input auto . pack <=< makeAbsolute