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

Commit 1ede5298d8d06bcaff650918a0f8574e5eb029b4
Parent: c9895884e73b2dfd643edc7e868802de1787c955
Author: mcol <mcol@posteo.net>
Date: 2021-12-05 00:25:25 +0300
Committer: mcol <mcol@posteo.net>
Committed: 2021-12-05 00:25:25 +0300

Skip outputting files if an output file exists for HEAD

src/Repositories.hs Modified

@@ -104,32 +104,39 @@
         Just commitID -> do
             let gitHead = Tagged commitID
 
-            -- Collect variables available in the ginger templates --
-            commits <- getCommits gitHead
-            tree <- getTree gitHead
-            tags <- getRefs "refs/tags/"
-            branches <- getRefs "refs/heads/"
-            let scope = package env repos name (repositoryDescription repo) commits tree tags branches
-
-            -- Create the destination folders --
-            commitDir <- liftIO . parseRelDir $ "commit"
-            fileDir <- liftIO . parseRelDir $ "file"
-            liftIO . ensureDir $ output </> commitDir
-            liftIO . ensureDir $ output </> fileDir
-
-            -- Run the generator --
-            let quiet = envQuiet env
-            let force = envForce env
-            mapM_ (genRepo output scope) $ envRepoTemplates env
-            mapM_ (genTarget output scope quiet force $ envCommitTemplate env) commits
-            mapM_ (genTarget output scope quiet True $ envFileTemplate env) tree -- TODO: detect file changes
-
-            -- Copy any static files/folders into the output folder --
-            liftIO . envRepoCopyStatics env $ output
+            -- If a page exists for the head commit, don't do anything else --
+            exists <-
+                liftIO . D.doesFileExist $
+                    toFilePath output FP.</> "commit" FP.</> show commitID <> ".html"
+
+            unless exists $ do
+                -- Collect variables available to the ginger templates --
+                commits <- getCommits gitHead
+                tree <- getTree gitHead
+                tags <- getRefs "refs/tags/"
+                branches <- getRefs "refs/heads/"
+                let scope = package env repos name (repositoryDescription repo) commits tree tags branches
+
+                -- Create the destination folders --
+                commitDir <- liftIO . parseRelDir $ "commit"
+                fileDir <- liftIO . parseRelDir $ "file"
+                liftIO . ensureDir $ output </> commitDir
+                liftIO . ensureDir $ output </> fileDir
+
+                -- Run the generator --
+                let quiet = envQuiet env
+                let force = envForce env
+                mapM_ (genRepo output scope) $ envRepoTemplates env
+                mapM_ (genTarget output scope quiet force $ envCommitTemplate env) commits
+                mapM_ (genTarget output scope quiet True $ envFileTemplate env) tree -- TODO: detect file changes
+
+                -- Copy any static files/folders into the output folder --
+                liftIO . envRepoCopyStatics env $ output
 
             -- Return the repo with the head so the index page can use it. --
+            repoHead <- lookupCommit gitHead -- Do this in case the block above is skipped.
             return
-                repo{repositoryHead = Just . head $ commits}
+                repo{repositoryHead = Just repoHead}
 
 {-
 The role of the function above is to gather information about a git repository and