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

Commit b06798837a4b6c52d3de2f7addd3325769fda6a6
Parent: 8612b175af634ee9ed541d6d6a8d828853b37dd7
Author: mcol <mcol@posteo.net>
Date: 2021-12-04 13:57:44 +0300
Committer: mcol <mcol@posteo.net>
Committed: 2021-12-04 13:57:44 +0300

Also copy static files/folders in repo/ into repo outputs

Closes #16

test/test.sh Modified

@@ -40,6 +40,8 @@
     "gitserve/file/test.expected.gitserve.file.html"
     "gitserve/file/test.templates.style.css.html"
     "gitserve/file/test.templates.so_called_binary_file.html"
+    "gitserve/log.html"
+    "gitserve/static/another_file"
 )
 
 stack run -- -c test/config.dhall -q || exit 1

test/templates/repo/static/another_file Added

@@ -0,0 +1 @@
+this one is in repo/

test/templates/repo/log.html Added

@@ -0,0 +1 @@
+index.html
\ No newline at end of file

test/expected/gitserve/static/another_file Added

@@ -0,0 +1 @@
+this one is in repo/

test/expected/gitserve/log.html Added

@@ -0,0 +1 @@
+index.html
\ No newline at end of file

src/Repositories.hs Modified

@@ -110,7 +110,7 @@
             branches <- getRefs "refs/heads/"
             let scope = package env repos name (repositoryDescription repo) commits tree tags branches
 
-            -- Create the destination folders
+            -- Create the destination folders --
             commitDir <- liftIO . parseRelDir $ "commit"
             fileDir <- liftIO . parseRelDir $ "file"
             liftIO . ensureDir $ output </> commitDir
@@ -123,6 +123,9 @@
             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. --
             return
                 repo{repositoryHead = Just . head $ commits}

src/Env.hs Modified

@@ -77,6 +77,7 @@
     , envHost :: T.Text
     , envQuiet :: Bool
     , envForce :: Bool
+    , envRepoCopyStatics :: Path Abs Dir -> IO ()
     }
 
 {-
@@ -99,9 +100,9 @@
 
     -- Find template files, copying the static files as is
     (dirs, files) <- ls . confTemplate $ config
-    (_, filesRepo) <- ls $ confTemplate config FP.</> "repo"
-    copyStaticDirs output dirs
-    copyStaticFiles output files
+    (dirsRepo, filesRepo) <- ls $ confTemplate config FP.</> "repo"
+    copyStaticDirs dirs output
+    copyStaticFiles files output
 
     -- Load files from template directory
     indexT <- collectTemplates files
@@ -134,6 +135,7 @@
             , envHost = confHost config
             , envQuiet = quiet
             , envForce = force
+            , envRepoCopyStatics = \p -> copyStaticDirs dirsRepo p >> copyStaticFiles filesRepo p
             }
   where
     ls :: FilePath -> IO ([Path Abs Dir], [Path Abs File])
@@ -170,8 +172,8 @@
 link intact, resulting in a symbolic link at `output/link.html` essentially
 pointing to `output/gitserve/index.html`.
 -}
-copyStaticDirs :: Path Abs Dir -> [Path Abs Dir] -> IO ()
-copyStaticDirs output = mapM_ copy
+copyStaticDirs :: [Path Abs Dir] -> Path Abs Dir -> IO ()
+copyStaticDirs dirs output = mapM_ copy dirs
   where
     copy :: Path Abs Dir -> IO ()
     copy p = do
@@ -186,8 +188,8 @@
                     createDirectoryLink target . FP.dropTrailingPathSeparator . toFilePath $ output'
                 else copyDirRecur p output'
 
-copyStaticFiles :: Path Abs Dir -> [Path Abs File] -> IO ()
-copyStaticFiles output = mapM_ copy
+copyStaticFiles :: [Path Abs File] -> Path Abs Dir -> IO ()
+copyStaticFiles files output = mapM_ copy files
   where
     copy :: Path Abs File -> IO ()
     copy p = do