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

Commit f92c012b5251e34cf712c27790ddf690ae23ab7b
Parent: 35031ef128de801d323c110ecf730b19023eeb64
Author: mcol <mcol@posteo.net>
Date: 2021-09-19 21:47:23 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2021-09-19 21:47:23 +0100

Read repo description from file

src/Repositories.hs Modified

@@ -13,6 +13,7 @@
 import Git.Libgit2 (lgFactory, LgRepo)
 import System.Directory (createDirectoryIfMissing)
 import System.FilePath ((</>), takeFileName)
+import System.IO.Error (tryIOError)
 import Text.Ginger (runGingerT, makeContextHtmlM, toGVal, GVal)
 import Text.Ginger.Html (htmlSource)
 
@@ -41,6 +42,7 @@
     case ref of
         Nothing -> liftIO . print $ "gitserve: " <> (takeFileName path) <> ": Failed to resolve HEAD."
         Just commitID -> do
+            description <- liftIO $ getDescription $ outPath </> "description"
             head <- lookupCommit (Tagged commitID)
             nodes <- lookupTree (commitTree head) >>= listTreeEntries
             return ()
@@ -49,6 +51,12 @@
 
     --mconcat $ runGingerT (makeContextHtmlM (scopeLookup context) (putStr . unpack . htmlSource)) tpl
 
+getDescription :: FilePath -> IO (Maybe String)
+getDescription path = tryIOError (readFile path) >>= \e ->
+    case e of
+        Right contents -> return $ Just contents
+        Left err -> return Nothing
+
 -- Variables:
 --title = "gitserve"
 --description = ""