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

Commit 05a183562b5469348078df3a24d2ba0876c7e50a
Parent: 5778e56f81619179068a193b1b3759bfea6eef39
Author: mcol <mcol@posteo.net>
Date: 2021-11-26 00:20:14 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-11-26 00:21:23 +0000

Make repo list available in all templates

Closes #8

src/Repositories.hs Modified

@@ -36,7 +36,9 @@
 their web pages using the loaded templates.
 -}
 run :: Env -> IO [Repo]
-run env = mapM (processRepo env) =<< loadRepos env
+run env = do
+    repos <- loadRepos env
+    mapM (processRepo env repos) repos
 
 ----------------------------------------------------------------------------------------
 -- Private -----------------------------------------------------------------------------
@@ -61,11 +63,12 @@
 repository doesn't exist or is unreadable in any way we can forget about it and move on
 (after informing the user of course).
 -}
-processRepo :: Env -> Repo -> IO Repo
-processRepo env repo = withRepository lgFactory (toFilePath . repositoryPath $ repo) $ processRepo' env repo
+processRepo :: Env -> [Repo] -> Repo -> IO Repo
+processRepo env repos repo =
+    withRepository lgFactory (toFilePath . repositoryPath $ repo) $ processRepo' env repos repo
 
-processRepo' :: Env -> Repo -> ReaderT LgRepo IO Repo
-processRepo' env repo = do
+processRepo' :: Env -> [Repo] -> Repo -> ReaderT LgRepo IO Repo
+processRepo' env repos repo = do
     let name = dirname . repositoryPath $ repo
     let output = envOutputDirectory env </> name
 
@@ -81,7 +84,7 @@
             tree <- getTree gitHead
             tags <- getRefs "refs/tags/"
             branches <- getRefs "refs/heads/"
-            let scope = package env name (repositoryDescription repo) commits tree tags branches
+            let scope = package env repos name (repositoryDescription repo) commits tree tags branches
 
             -- Create the destination folders
             commitDir <- liftIO . parseRelDir $ "commit"
@@ -97,7 +100,8 @@
             mapM_ (genTarget output scope quiet True $ envFileTemplate env) tree -- TODO: detect file changes
 
             -- Return the repo with the head so the index page can use it. --
-            return $ repo{repositoryHead = Just . head $ commits}
+            return
+                repo{repositoryHead = Just . head $ commits}
 
 {-
 The role of the function above is to gather information about a git repository and
@@ -107,6 +111,7 @@
 -}
 package ::
     Env ->
+    [Repo] ->
     Path Rel Dir ->
     Text ->
     [Commit LgRepo] ->
@@ -114,9 +119,10 @@
     [Ref] ->
     [Ref] ->
     HashMap.HashMap Text (GVal RunRepo)
-package env name description commits tree tags branches =
+package env repos name description commits tree tags branches =
     HashMap.fromList
         [ ("host", toGVal . envHost $ env)
+        , ("repos", toGVal repos)
         , ("name", toGVal . pack . init . toFilePath $ name)
         , ("description", toGVal description)
         , ("commits", toGVal . reverse $ commits) -- Could be optimised