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

Commit 89f88018a8a2e54ed3be646ef2873693bbf3e30d
Parent: 02caf075c48c382a507fa89983d40e45636a3821
Author: mcol <mcol@posteo.net>
Date: 2021-09-18 21:36:38 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2021-09-18 21:36:38 +0100

Create output folder for repo if it doesn't exist

src/Repositories.hs Modified

@@ -9,10 +9,11 @@
 import Data.Tagged
 import Git
 import Git.Libgit2 (lgFactory)
-import System.FilePath (takeFileName)
+import System.Directory (createDirectoryIfMissing)
+import System.FilePath ((</>), takeFileName)
 import Text.Ginger (easyRender)
 
-import Config (Config, repoPaths)
+import Config (Config, repoPaths, outputDirectory)
 import Templates (Template, templateGinger, templatePath)
 
 {-
@@ -21,7 +22,7 @@
 templates.
 -}
 run :: Config -> [Template] -> IO ()
-run config templates = foldMap (processRepo templates) . repoPaths $ config
+run config templates = foldMap (processRepo templates $ outputDirectory config) . repoPaths $ config
 
 ----------------------------------------------------------------------------------------
 
@@ -30,14 +31,17 @@
 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 :: [Template] -> FilePath -> IO ()
-processRepo templates path = withRepository lgFactory path $ do
+processRepo :: [Template] -> FilePath -> FilePath -> IO ()
+processRepo templates outputDirectory path = withRepository lgFactory path $ do
+    return $ createDirectoryIfMissing True outPath
     maybeObjID <- resolveReference "HEAD"
     case maybeObjID of
         Just commitID -> do
             headCommit <- lookupCommit (Tagged commitID)
             liftIO $ print $ commitLog headCommit
         _ -> liftIO $ print $ "gitserve: " <> (takeFileName path) <> ": Failed to resolve HEAD."
+  where
+    outPath = outputDirectory </> (takeFileName path)
 
 -- Variables:
 title = "gitserve"