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

Commit 9231c16355a66cdd5a9dfad94c9f7d61ecaaef35
Parent: 6b5407a36db1337cf9728f8e2c6560dcecfafd9d
Author: mcol <mcol@posteo.net>
Date: 2021-09-30 22:42:53 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2021-09-30 22:42:53 +0100

Create base haskmap for all of a repo's variables

src/Repositories.hs Modified

@@ -75,12 +75,10 @@
             tree <- getTree gitHead
 
             -- Run the generator --
-            let repo = package env name description commits tree
-            liftIO . mapM (generate output repo) $ envTemplates env
-            let commitScope = packageCommit env name description
-            liftIO . mapM (generateCommit output commitScope $ envCommitTemplate env) $ commits
-            let fileScope = packageFile env name description
-            liftIO . mapM (generateFile output fileScope $ envFileTemplate env) $ tree
+            let scope = package env name description commits tree
+            liftIO . mapM (generate output scope) $ envTemplates env
+            liftIO . mapM (generateCommit output scope $ envCommitTemplate env) $ commits
+            liftIO . mapM (generateFile output scope $ envFileTemplate env) $ tree
             return ()
 
 {-
@@ -228,7 +226,7 @@
 
 generateCommit
     :: FilePath
-    -> (Commit LgRepo -> HashMap.HashMap Text (GVal (Run SourcePos IO Html)))
+    -> HashMap.HashMap Text (GVal (Run SourcePos IO Html))
     -> Maybe Template
     -> Commit LgRepo
     -> IO ()
@@ -236,28 +234,16 @@
 generateCommit output scope (Just template) commit = do
     let hash = unpack . renderObjOid . commitOid $ commit
     let template' = template { templatePath = hash ++ ".html" }
+    let scope' = scope <> HashMap.fromList [("commit", toGVal commit)]
     liftIO $ createDirectoryIfMissing True (output </> "commits")
-    generate (output </> "commits") (scope commit) template'
+    generate (output </> "commits") scope' template'
     return ()
 
-packageCommit
-    :: Env
-    -> FilePath
-    -> Text
-    -> Commit LgRepo
-    -> HashMap.HashMap Text (GVal (Run SourcePos IO Html))
-packageCommit env name description commit = HashMap.fromList
-    [ ("host", toGVal . host . envConfig $ env)
-    , ("name", toGVal . pack $ name)
-    , ("description", toGVal description)
-    , ("commit", toGVal commit)
-    ]
-
 -- TODO: DRY
 
 generateFile
     :: FilePath
-    -> (TreeFile -> HashMap.HashMap Text (GVal (Run SourcePos IO Html)))
+    -> HashMap.HashMap Text (GVal (Run SourcePos IO Html))
     -> Maybe Template
     -> TreeFile
     -> IO ()
@@ -265,19 +251,7 @@
 generateFile output scope (Just template) file = do
     let path = unpack . replace "/" "." . decodeUtf8 . treeFilePath $ file
     let template' = template { templatePath = path ++ ".html" }
+    let scope' = scope <> HashMap.fromList [("file", toGVal file)]
     liftIO $ createDirectoryIfMissing True (output </> "files")
-    generate (output </> "files") (scope file) template'
+    generate (output </> "files") scope' template'
     return ()
-
-packageFile
-    :: Env
-    -> FilePath
-    -> Text
-    -> TreeFile
-    -> HashMap.HashMap Text (GVal (Run SourcePos IO Html))
-packageFile env name description file = HashMap.fromList
-    [ ("host", toGVal . host . envConfig $ env)
-    , ("name", toGVal . pack $ name)
-    , ("description", toGVal description)
-    , ("file", toGVal file)
-    ]