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

Commit c20a13d6002297673ba7ecb369154d8475647728
Parent: 37ae3b428095f9eb2c235bc32a6fbcc137084118
Author: mcol <mcol@posteo.net>
Date: 2022-05-29 01:45:59 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2022-05-29 01:45:59 +0100

qualify all Text usage to avoid confusion with lazy vs strict

src/Types.hs Modified

@@ -16,7 +16,6 @@
 import Data.Default (def)
 import Data.Maybe (fromMaybe, listToMaybe)
 import Data.Tagged (untag)
-import Data.Text (Text, pack, strip)
 import qualified Data.Text as T
 import Data.Text.Encoding (decodeUtf8With)
 import Data.Text.Encoding.Error (lenientDecode)
@@ -39,7 +38,7 @@
 unquote :: String -> String
 unquote = init . tail
 
-bsToText :: ByteString -> Text
+bsToText :: ByteString -> T.Text
 bsToText = decodeUtf8With lenientDecode
 
 {-
@@ -48,7 +47,7 @@
 -}
 data Repo = Repo
     { repositoryPath :: Path Abs Dir
-    , repositoryDescription :: Text
+    , repositoryDescription :: T.Text
     , repositoryHead :: Maybe Commit
     }
 
@@ -60,12 +59,12 @@
     toGVal :: Repo -> GVal m
     toGVal repo =
         def
-            { asHtml = html . pack . init . unquote . show . dirname . repositoryPath $ repo
-            , asText = pack . show . dirname . repositoryPath $ repo
+            { asHtml = html . T.pack . init . unquote . show . dirname . repositoryPath $ repo
+            , asText = T.pack . show . dirname . repositoryPath $ repo
             , asLookup = Just . repoAsLookup $ repo
             }
 
-repoAsLookup :: Repo -> Text -> Maybe (GVal m)
+repoAsLookup :: Repo -> T.Text -> Maybe (GVal m)
 repoAsLookup repo = \case
     "name" -> Just . toGVal . init . unquote . show . dirname . repositoryPath $ repo
     "description" -> Just . toGVal . repositoryDescription $ repo
@@ -85,25 +84,25 @@
     toGVal :: Commit -> GVal m
     toGVal commit =
         def
-            { asHtml = html . strip . T.takeWhile (/= '\n') . Git.commitLog . commitGit $ commit
-            , asText = pack . show . Git.commitLog . commitGit $ commit
+            { asHtml = html . T.strip . T.takeWhile (/= '\n') . Git.commitLog . commitGit $ commit
+            , asText = T.pack . show . Git.commitLog . commitGit $ commit
             , asLookup = Just . commitAsLookup $ commit
             }
 
-commitAsLookup :: Commit -> Text -> Maybe (GVal m)
+commitAsLookup :: Commit -> T.Text -> Maybe (GVal m)
 commitAsLookup commit = \case
     "id" -> Just . toGVal . show . untag . Git.commitOid . commitGit $ commit
     "href" -> Just . toGVal . (<> ".html") . show . untag . Git.commitOid . commitGit $ commit
-    "title" -> Just . toGVal . strip . T.takeWhile (/= '\n') . Git.commitLog . commitGit $ commit
-    "body" -> Just . toGVal . strip . T.dropWhile (/= '\n') . Git.commitLog . commitGit $ commit
-    "message" -> Just . toGVal . strip . Git.commitLog . commitGit $ commit
-    "author" -> Just . toGVal . strip . Git.signatureName . Git.commitAuthor . commitGit $ commit
-    "committer" -> Just . toGVal . strip . Git.signatureName . Git.commitCommitter . commitGit $ commit
-    "author_email" -> Just . toGVal . strip . Git.signatureEmail . Git.commitAuthor . commitGit $ commit
-    "committer_email" -> Just . toGVal . strip . Git.signatureEmail . Git.commitCommitter . commitGit $ commit
+    "title" -> Just . toGVal . T.strip . T.takeWhile (/= '\n') . Git.commitLog . commitGit $ commit
+    "body" -> Just . toGVal . T.strip . T.dropWhile (/= '\n') . Git.commitLog . commitGit $ commit
+    "message" -> Just . toGVal . T.strip . Git.commitLog . commitGit $ commit
+    "author" -> Just . toGVal . T.strip . Git.signatureName . Git.commitAuthor . commitGit $ commit
+    "committer" -> Just . toGVal . T.strip . Git.signatureName . Git.commitCommitter . commitGit $ commit
+    "author_email" -> Just . toGVal . T.strip . Git.signatureEmail . Git.commitAuthor . commitGit $ commit
+    "committer_email" -> Just . toGVal . T.strip . Git.signatureEmail . Git.commitCommitter . commitGit $ commit
     "authored" -> Just . toGVal . show . Git.signatureWhen . Git.commitAuthor . commitGit $ commit
     "committed" -> Just . toGVal . show . Git.signatureWhen . Git.commitCommitter . commitGit $ commit
-    "encoding" -> Just . toGVal . strip . Git.commitEncoding . commitGit $ commit
+    "encoding" -> Just . toGVal . T.strip . Git.commitEncoding . commitGit $ commit
     "parent" -> toGVal . show . untag <$> (listToMaybe . Git.commitParents . commitGit $ commit)
     "diffs" -> Just . toGVal . commitDiffs $ commit
     _ -> Nothing
@@ -151,7 +150,7 @@
             , asLookup = Just . diffAsLookup $ diff
             }
 
-diffAsLookup :: Diff -> Text -> Maybe (GVal m)
+diffAsLookup :: Diff -> T.Text -> Maybe (GVal m)
 diffAsLookup diff = \case
     "new_file" -> Just . toGVal . diffNewFile $ diff
     "old_file" -> toGVal <$> diffOldFile diff
@@ -168,7 +167,7 @@
             , asLookup = Just . hunkAsLookup $ hunk
             }
 
-hunkAsLookup :: Hunk -> Text -> Maybe (GVal m)
+hunkAsLookup :: Hunk -> T.Text -> Maybe (GVal m)
 hunkAsLookup hunk = \case
     "lines" -> Just . toGVal . fmap makeLine . hunkLines $ hunk
     "header" -> Just . toGVal . bsToText . hunkHeader $ hunk
@@ -191,7 +190,7 @@
 convenience for assigning CSS classes.
 -}
 data Line = Line
-    { lineText :: Text
+    { lineText :: T.Text
     , lineClass :: String
     }
 
@@ -204,7 +203,7 @@
             , asLookup = Just . lineAsLookup $ line
             }
 
-lineAsLookup :: Line -> Text -> Maybe (GVal m)
+lineAsLookup :: Line -> T.Text -> Maybe (GVal m)
 lineAsLookup line = \case
     "text" -> Just . toGVal . lineText $ line
     "class" -> Just . toGVal . lineClass $ line
@@ -215,7 +214,7 @@
 objects contained therein.
 -}
 data TreeFile = TreeFile
-    { treeFilePath :: Text
+    { treeFilePath :: T.Text
     , treeFileContents :: TreeFileContents
     , treeFileMode :: TreeEntryMode
     }
@@ -273,12 +272,12 @@
     toGVal (FileContents bytestring) = toGVal bytestring
     toGVal (FolderContents treeFiles) =
         def
-            { asHtml = html . pack . show . fmap treeFilePath $ treeFiles
-            , asText = pack . show . fmap treeFilePath $ treeFiles
+            { asHtml = html . T.pack . show . fmap treeFilePath $ treeFiles
+            , asText = T.pack . show . fmap treeFilePath $ treeFiles
             , asList = Just . fmap toGVal $ treeFiles
             }
 
-treeAsLookup :: TreeFile -> Text -> Maybe (GVal m)
+treeAsLookup :: TreeFile -> T.Text -> Maybe (GVal m)
 treeAsLookup treefile = \case
     "path" -> Just . toGVal . treeFilePath $ treefile
     "name" -> Just . toGVal . FP.takeFileName . T.unpack . treeFilePath $ treefile
@@ -293,7 +292,7 @@
     "is_directory" -> Just . toGVal . treeFileIsDirectory $ treefile
     _ -> Nothing
   where
-    treeFileGetTree :: Text -> TreeFileContents -> [TreeFile]
+    treeFileGetTree :: T.Text -> TreeFileContents -> [TreeFile]
     treeFileGetTree parent (FolderContents fs) = filter atTop fs
       where
         atTop = notElem FP.pathSeparator . drop 1 . T.unpack . fromMaybe "" . T.stripPrefix parent . treeFilePath
@@ -330,7 +329,7 @@
 {-
 Get the name of a tree file path's HTML file. Leading periods are dropped.
 -}
-treePathToHref :: TreeFile -> Text
+treePathToHref :: TreeFile -> T.Text
 treePathToHref = T.dropWhile (== '.') . flip T.append ".html" . T.replace "/" "." . treeFilePath
 
 {-
@@ -350,7 +349,7 @@
             , asLookup = Just . refAsLookup $ ref
             }
 
-refAsLookup :: Ref -> Text -> Maybe (GVal m)
+refAsLookup :: Ref -> T.Text -> Maybe (GVal m)
 refAsLookup ref = \case
     "name" -> Just . toGVal . refName $ ref
     "commit" -> Just . toGVal . refCommit $ ref

src/Templates.hs Modified

@@ -10,7 +10,7 @@
 import qualified Data.HashMap.Strict as HashMap
 import Data.IORef (modifyIORef', newIORef, readIORef)
 import qualified Data.Text as T
-import Data.Text.Lazy (Text)
+import qualified Data.Text.Lazy as TL
 import qualified Data.Text.Lazy.Builder as TB
 import Path (Abs, File, Path, Rel, filename, toFilePath)
 import System.IO.Error (tryIOError)
@@ -56,7 +56,7 @@
 generate ::
     Template ->
     HashMap.HashMap T.Text (GVal RunRepo) ->
-    IO Text
+    IO TL.Text
 generate template scope = do
     ioref <- newIORef . TB.fromText $ ""
 

src/Repositories.hs Modified

@@ -25,7 +25,6 @@
 import Data.List (find)
 import Data.Maybe (catMaybes, fromJust, listToMaybe, mapMaybe)
 import Data.Tagged (Tagged (..), untag)
-import Data.Text (Text)
 import qualified Data.Text as T
 import qualified Data.Text.Encoding as T
 import qualified Data.Text.Encoding.Error as T
@@ -77,7 +76,7 @@
     3. Fallback to the repo folder's name.
 
 -}
-getDescription :: Path Abs Dir -> IO Text
+getDescription :: Path Abs Dir -> IO T.Text
 getDescription dir =
     ifM
         (D.doesFileExist inTop)
@@ -147,7 +146,7 @@
                     gen ::
                         ToGVal RunRepo t =>
                         Template ->
-                        Text ->
+                        T.Text ->
                         Path Abs Dir ->
                         (t -> FilePath) ->
                         t ->
@@ -178,12 +177,12 @@
     Env ->
     [Repo] ->
     Path Rel Dir ->
-    Text ->
+    T.Text ->
     [Commit] ->
     [TreeFile] ->
     [Ref] ->
     [Ref] ->
-    HashMap.HashMap Text (GVal RunRepo)
+    HashMap.HashMap T.Text (GVal RunRepo)
 package env repos name description commits tree tags branches =
     HashMap.fromList
         [ ("host", toGVal . envHost $ env)
@@ -201,7 +200,7 @@
   where
     -- Find a file in the tree starting with the specified prefix. The prefix is looked
     -- for on the full path, so will only find files in the top level directory.
-    findFile :: Text -> [TreeFile] -> Maybe TreeFile
+    findFile :: T.Text -> [TreeFile] -> Maybe TreeFile
     findFile prefix = find (T.isPrefixOf prefix . T.toLower . treeFilePath)
 
 {-
@@ -337,14 +336,14 @@
     getEntryModes (Git.TreeEntry _) = return ModeDirectory
     getEntryModes (Git.CommitEntry _) = return ModeSubmodule
 
-    treePaths :: (Git.TreeFilePath, Git.TreeEntry LgRepo) -> Text
+    treePaths :: (Git.TreeFilePath, Git.TreeEntry LgRepo) -> T.Text
     treePaths = T.decodeUtf8With T.lenientDecode . fst
 
 {-
 Collect information about references. TODO: Find a more canonical way to split
 references into tags or branches rather than filtering the refnames.
 -}
-getRefs :: Text -> ReaderT LgRepo IO [Ref]
+getRefs :: T.Text -> ReaderT LgRepo IO [Ref]
 getRefs ref = do
     names <- filter (T.isPrefixOf ref) <$> Git.listReferences
     maybeOids <- mapM Git.resolveReference names
@@ -366,7 +365,7 @@
 
 genRepo ::
     Path Abs Dir ->
-    HashMap.HashMap Text (GVal RunRepo) ->
+    HashMap.HashMap T.Text (GVal RunRepo) ->
     Template ->
     IO ()
 genRepo output scope template =
@@ -391,11 +390,11 @@
 
 genTarget ::
     ToGVal RunRepo t =>
-    HashMap.HashMap Text (GVal RunRepo) ->
+    HashMap.HashMap T.Text (GVal RunRepo) ->
     Bool ->
     Bool ->
     Template ->
-    Text ->
+    T.Text ->
     Path Abs Dir ->
     (t -> FilePath) ->
     t ->

src/Index.hs Modified

@@ -6,7 +6,7 @@
 
 import Control.Monad (unless)
 import qualified Data.HashMap.Strict as HashMap
-import Data.Text (Text)
+import qualified Data.Text as T
 import qualified Data.Text.Lazy.IO as TL
 import Path (toFilePath)
 import System.FilePath (combine)
@@ -35,7 +35,7 @@
 packageIndex ::
     Env ->
     [Repo] ->
-    HashMap.HashMap Text (GVal RunRepo)
+    HashMap.HashMap T.Text (GVal RunRepo)
 packageIndex env repos =
     HashMap.fromList
         [ ("host", toGVal $ envHost env)

src/Env.hs Modified

@@ -15,7 +15,6 @@
 import Control.Monad (filterM, join, when, (<=<))
 import Control.Monad.Extra (findM)
 import Data.Maybe (catMaybes, fromMaybe, isNothing)
-import Data.Text (pack)
 import qualified Data.Text as T
 import Dhall
 import Dhall.Deriving
@@ -60,7 +59,7 @@
         via Codec (Field (CamelCase <<< DropPrefix "conf")) Config
 
 getConfig :: String -> IO Config
-getConfig = input auto . pack <=< makeAbsolute
+getConfig = input auto . T.pack <=< makeAbsolute
 
 {-
 The Env data type represents all of the program's state, including user configuration