Commit edff811793f7c3f487c6373445b44149fc3385e5 Parent: 4952859082289144fbf3bb7f6b0bf0b16f5e938f Author: mcol <mcol@posteo.net> Date: 2021-11-30 02:29:14 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-11-30 02:29:14 +0000 Add `gitserve -t` to output a plain config and base template. The assets are embedded into the compiled binary.
templates/base/style.css Added
@@ -0,0 +1 @@
+TODO
templates/base/index.html Added
@@ -0,0 +1 @@
+TODO
templates/README.rst Modified
@@ -14,6 +14,7 @@ ============= ========================================== Template name Description ============= ========================================== +base This is placed into the current folder via ``gitserve -t``. docs This is used for generating gitserve's docs website. stagit This replicates much of stagit_'s style. ============= ==========================================
src/config.dhall Added
@@ -0,0 +1,24 @@ +-- This is an example configuration file for gitserve. +-- It uses the Dhall configuration language: dhall-lang.org + +-- You can list the git repositories here. +-- These will be used to generate HTML. +let repos = ".." + +let folders = + [ "${repos}/gitserve" + ] + +-- These are the configurable options that are used by gitserve. +-- You may want to replace the relative paths for absolute paths. +let config = + { repoPaths = folders + , templateDirectory = "./template" + , outputDirectory = "./output" + , host = "http://localhost:8000" + } + +-- Note: The host is available verbatim in templates. +-- Port 8000 is appended here for easier testing with `python -m http.server`. + +in config
src/Main.hs Modified
@@ -1,4 +1,6 @@ +{-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} module Main ( main, @@ -6,8 +8,13 @@ import Paths_gitserve (version) +import qualified Data.ByteString as B +import qualified Data.ByteString.UTF8 as B +import Data.FileEmbed (embedDir, embedFile) import Data.Version (showVersion) import qualified Options.Applicative as O +import qualified System.Directory as D +import System.FilePath (takeDirectory, (</>)) import Config (getConfig) import Index (runIndex) @@ -21,6 +28,7 @@ { optConfig :: FilePath , optQuiet :: Bool , optForce :: Bool + , optTemplate :: Bool , optVersion :: Bool } @@ -45,6 +53,11 @@ <> O.help "Force regeneration of all files." ) <*> O.switch + ( O.long "template" + <> O.short 't' + <> O.help "Create a template and config in the current folder." + ) + <*> O.switch ( O.long "version" <> O.short 'v' <> O.help "Print the gitserve's version." @@ -55,7 +68,7 @@ O.execParser $ O.info (opts O.<**> O.helper) - ( O.progDesc "🐙 Templated web page generator for your git repositories" + ( O.progDesc . B.toString $ $(embedFile "description") ) {- @@ -64,9 +77,38 @@ main :: IO () main = do options <- parser - if optVersion options - then putStrLn $ "Your gitserve version is: " <> showVersion version - else do - conf <- getConfig (optConfig options) - env <- loadEnv (optQuiet options) (optForce options) conf - runIndex env =<< run env + if + | optVersion options -> + putStrLn $ "Your gitserve version is: " <> showVersion version + | optTemplate options -> + makeTemplate + | otherwise -> do + conf <- getConfig (optConfig options) + env <- loadEnv (optQuiet options) (optForce options) conf + runIndex env =<< run env + +{- +Put a base template and plain config into the current directory. +-} +makeTemplate :: IO () +makeTemplate = do + tExists <- D.doesPathExist "./template" + cExists <- D.doesPathExist "./config.dhall" + if + | tExists -> putStrLn "Failed - './template' already exists." + | cExists -> putStrLn "Failed - './config.dhall' already exists." + | otherwise -> do + mapM_ (uncurry place) base + B.writeFile "./config.dhall" config + where + base :: [(FilePath, B.ByteString)] + base = $(embedDir "templates/base") + + config :: B.ByteString + config = $(embedFile "src/config.dhall") + + place :: FilePath -> B.ByteString -> IO () + place path bytes = do + let path' = "template" </> path + D.createDirectoryIfMissing True . takeDirectory $ path' + B.writeFile path' bytes
gitserve.cabal Modified
@@ -21,10 +21,12 @@ default-language: Haskell2010 build-depends: base >= 4.7 && < 5 , conduit + , bytestring , data-default , dhall , directory , extra + , file-embed , filepath , ginger >= 0.10.3.0 , gitlib
Makefile Modified
@@ -14,7 +14,7 @@ .PHONY: format format: ## Auto-format the source code - @fourmolu -m inplace src/* + @fourmolu -m inplace src/*.hs .PHONY: install install: ## Install the compiled executable