Commit 174d8aaaea29ef5cc1aecd98ab2cefe1d72aad5a Parent: d8a16891b85e1bcf43e78c426aab5f937a4311a8 Author: mcol <mcol@posteo.net> Date: 2021-12-04 00:24:29 +0300 Committer: mcol <mcol@posteo.net> Committed: 2021-12-04 00:24:29 +0300 Make config options nicer
test/config.dhall Modified
@@ -1,8 +1,8 @@ let config = - { repoPaths = ["."] - , scanRepoPaths = False - , templateDirectory = "./test/templates" - , outputDirectory = "./test/result" + { repos = ["."] + , scan = False + , template = "./test/templates" + , output = "./test/result" , host = "https://github.com/m-col/gitserve" }
templates/README.rst Modified
@@ -4,7 +4,7 @@ This folder contains some example templates for demonstration purposes. They can be used for generation by specifying the path of one of the folders in -the ``gitserve`` configuration file as the ``templateDirectory``. +the configuration file as the ``template``. If you make a nice template and would like to share it, contributions of more folders here would be very welcome!
src/config.dhall Modified
@@ -12,13 +12,17 @@ -- 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 - , scanRepoPaths = True - , templateDirectory = "./template" - , outputDirectory = "./output" + { repos = folders + , scan = False + , template = "./template" + , output = "./output" , host = "http://localhost:8000" } +-- If `scan` is True, then gitserve will look for git repositories in folders +-- nested within those listed in `repos`. Otherwise, the folders in `repos` are +-- assumed to be repositories themselves. + -- Note: The host is available verbatim in templates. -- Port 8000 is appended here for easier testing with `python -m http.server`.
src/Templates.hs Modified
@@ -59,8 +59,8 @@ , envCommitTemplate :: Maybe Template , envFileTemplate :: Maybe Template , envRepoTemplates :: [Template] - , envOutputDirectory :: Path Abs Dir - , envRepoPaths :: [Path Abs Dir] + , envOutput :: Path Abs Dir + , envRepos :: [Path Abs Dir] , envHost :: T.Text , envQuiet :: Bool , envForce :: Bool @@ -78,20 +78,20 @@ loadEnv :: Bool -> Bool -> Config -> IO Env loadEnv quiet force config = do -- First ensure that the output directory exists - output <- parseAbsDir <=< canonicalizePath . confOutputDirectory $ config + output <- parseAbsDir <=< canonicalizePath . confOutput $ config ensureDir output -- Parse repos for env - repoPaths <- - if confScanRepoPaths config + repos <- + if confScan config then do - ps <- fmap concat . mapM (fmap fst . ls) . confRepoPaths $ config + ps <- fmap concat . mapM (fmap fst . ls) . confRepos $ config return . filter ((/=) ".git" . toFilePath . dirname) $ ps - else mapM (parseAbsDir <=< canonicalizePath) . confRepoPaths $ config + else mapM (parseAbsDir <=< canonicalizePath) . confRepos $ config -- Find template files, copying the static files as is - (dirs, files) <- ls . confTemplateDirectory $ config - (_, filesRepo) <- ls $ confTemplateDirectory config FP.</> "repo" + (dirs, files) <- ls . confTemplate $ config + (_, filesRepo) <- ls $ confTemplate config FP.</> "repo" copyStaticDirs output dirs copyStaticFiles output files @@ -112,8 +112,8 @@ , envCommitTemplate = commitT , envFileTemplate = fileT , envRepoTemplates = repoT - , envOutputDirectory = output - , envRepoPaths = repoPaths + , envOutput = output + , envRepos = repos , envHost = confHost config , envQuiet = quiet , envForce = force @@ -187,15 +187,15 @@ {- The logic for copying static files and folders. Any file or folder in the -``confTemplateDirectory`` is considered static if: +``confTemplate`` is considered static if: - it is a symbolic link, or - it does not end in ".html" or ".include". Symbolic links are not followed and are copied as is. This means that a symbolic link -from `confTemplateDirectory/link.html` to `gitserve/index.html` will be copied, keeping the -link intact, resulting in a symbolic link at `outputDirectory/link.html` essentially -pointing to `outputDirectory/gitserve/index.html`. +from `confTemplate/link.html` to `gitserve/index.html` will be copied, keeping the +link intact, resulting in a symbolic link at `output/link.html` essentially +pointing to `output/gitserve/index.html`. -} -- TODO: merge isStatic and copy so it's just one step copyStaticDirs :: Path Abs Dir -> [Path Abs Dir] -> IO ()
src/Repositories.hs Modified
@@ -46,7 +46,7 @@ -} loadRepos :: Env -> IO [Repo] loadRepos env = do - paths' <- filterM (fmap isRight . okRepo) . envRepoPaths $ env + paths' <- filterM (fmap isRight . okRepo) . envRepos $ env descs <- mapM getDescription paths' return . fmap ($ Nothing) . zipWith Repo paths' $ descs where @@ -71,7 +71,7 @@ processRepo' :: Env -> [Repo] -> Repo -> ReaderT LgRepo IO Repo processRepo' env repos repo = do let name = dirname . repositoryPath $ repo - let output = envOutputDirectory env </> name + let output = envOutput env </> name resolveReference "HEAD" >>= \case Nothing -> do
src/Main.hs Modified
@@ -103,12 +103,12 @@ B.writeFile "./config.dhall" config putStrLn "A base template as been put at ./template." putStrLn "A plain config has been put at ./config.dhall" - putStrLn "Add a local git repository to repoPaths in the config" + putStrLn "Add a local git repository to 'repos' in the config" putStrLn "and run gitserve to generate HTML in ./output." oExists <- D.doesPathExist "./output" when oExists . putStrLn $ "WARNING: ./output ALREADY EXISTS AND WILL BE OVERWRITTEN\n" - <> "UNLESS YOU MOVE/RENAME IT OR CHANGE GITSERVE'S outputDirectory." + <> "UNLESS YOU MOVE/RENAME IT OR CHANGE GITSERVE'S output." where base :: [(FilePath, B.ByteString)] base = $(embedDir "templates/base")
src/Index.hs Modified
@@ -26,7 +26,7 @@ runIndexFile :: Env -> [Repo] -> Template -> IO () runIndexFile env repos template = do - let output = combine (toFilePath . envOutputDirectory $ env) . toFilePath . templatePath $ template + let output = combine (toFilePath . envOutput $ env) . toFilePath . templatePath $ template unless (envQuiet env) . putStrLn $ "Writing " <> output writeFile output "" -- Clear contents of file if it exists void $
src/Config.hs Modified
@@ -16,10 +16,10 @@ import System.Directory (makeAbsolute) data Config = Config - { confRepoPaths :: [FilePath] - , confScanRepoPaths :: Bool - , confTemplateDirectory :: FilePath - , confOutputDirectory :: FilePath + { confRepos :: [FilePath] + , confScan :: Bool + , confTemplate :: FilePath + , confOutput :: FilePath , confHost :: Text } deriving stock (Generic)
config.dhall Modified
@@ -12,13 +12,17 @@ -- These are the configurable options that are used by gitserve. -- If copying, you may want to replace the relative paths for absolute paths. let config = - { repoPaths = folders - , scanRepoPaths = False - , templateDirectory = "./templates/docs" - , outputDirectory = "./output" + { repos = folders + , scan = False + , template = "./templates/docs" + , output = "./output" , host = "http://localhost:8000" } +-- If `scan` is True, then gitserve will look for git repositories in folders +-- nested within those listed in `repos`. Otherwise, the folders in `repos` are +-- assumed to be repositories themselves. + -- Note: The host is available verbatim in templates. -- Port 8000 is appended here for easier testing with `python -m http.server`.
DOCUMENTATION.md Modified
@@ -16,13 +16,17 @@ It requires the following settings: -| Setting | Description | -| ------------------- | --------------------------------------------------- | -| `repoPaths` | A list of folders containing your git repositories. | -| `scanRepoPaths` | Whether `repoPaths` lists repos or folders containing nested repos. | -| `templateDirectory` | The folder containing the template (see below). | -| `outputDirectory` | Where to put the generated files. | -| `host` | The host URL, which is needed for creating links. | +| Setting | Description | +| ---------- | --------------------------------------------------------------- | +| `repos` | A list of folders containing your git repositories. | +| `scan` | Whether `repos` lists repos or folders containing nested repos. | +| `template` | The folder containing the template (see below). | +| `output` | Where to put the generated files. | +| `host` | The host URL, which is needed for creating links. | + +If `scan` is `True`, then gitserve will look for git repositories in folders +nested within those listed in `repos`. Otherwise, the folders in `repos` are +assumed to be repositories themselves. Then, pass the config file to gitserve. @@ -42,7 +46,7 @@ -v,--version Print the gitserve's version. -h,--help Show this help text -Note the "force" flag. By default, gitserve will not generate new output for +Note the `force` flag. By default, gitserve will not generate new output for commits to save time. This flag will force regeneration of all files, which would be needed if changes have been made to the template. @@ -69,7 +73,7 @@ To illustrate, this is the expected structure: - templateDirectory/ + template/ i_can_have_any_name.html and_there_can_be_any_number.html some_might_be_ginger_includes.html.include @@ -80,8 +84,8 @@ file.html commit.html -The top-level folder, here `templateDirectory`, is that which is specified in -the config file. +The top-level folder, here `template`, is that which is specified in the config +file. Files ending in ".html" directly within that folder have access to the *index scope*, and are each parsed exactly once and output into the output directory @@ -99,10 +103,10 @@ "file.html" and "commit.html". These have access to the *file scope* and *commit scope* respectively, and are parsed and output once per file or commit. -The resulting folder structure found in the `outputDirectory` will look like -this (if the only specified git repository is gitserve): +The resulting folder structure found in `output` will look like this (if +`repos` only contains gitserve): - outputDirectory/ + output/ i_can_have_any_name.html and_there_can_be_any_number.html non_html_is_fine.css @@ -121,10 +125,10 @@ Note: symbolic links are considered static and will be copied unchanged and unresolved from template to output. This means that, for example, a symlink at -`templateDirectory/index.html` pointing to `gitserve/index.html` will produce a -symlink at `outputDirectory/index.html` with the same behaviour, with the -effect that the served root index page will actually be the index page for the -`gitserve` repository (if present). +`template/index.html` pointing to `gitserve/index.html` will produce a symlink +at `output/index.html` with the same behaviour, with the effect that the served +root index page will actually be the index page for the `gitserve` repository +(if present). ### Scopes