From ce0b7ec230703d239b3d77e09352c0b1d515d8f5 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 21 Feb 2020 15:39:01 +0100 Subject: compiler: add gallery config file CLI argument GitHub: closes #136 --- compiler/app/Main.hs | 12 ++++++++++-- compiler/src/Compiler.hs | 16 +++++++++------- ldgallery.1.md | 4 ++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 753f281..1229e88 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -37,8 +37,9 @@ data ViewerConfig = ViewerConfig data Options = Options - { inputDir :: String - , outputDir :: String + { inputDir :: FilePath + , outputDir :: FilePath + , galleryConfig :: FilePath , rebuilAll :: Bool , cleanOutput :: Bool , withViewer :: Bool @@ -58,6 +59,12 @@ options = Options &= name "output-dir" &= explicit &= help "Generated gallery output path (default=./out)" + , galleryConfig = "" + &= typFile + &= name "g" + &= name "gallery-config" + &= explicit + &= help "Gallery configuration file (default=$input-dir/gallery.yaml)" , rebuilAll = False &= name "r" &= name "rebuild-all" @@ -99,6 +106,7 @@ main = buildGallery opts = checkDistinctPaths (inputDir opts) (outputDir opts) >> compileGallery + (galleryConfig opts) (inputDir opts) (galleryOutputDir opts) [outputDir opts] diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index bfefa63..bb0ee97 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -47,8 +47,8 @@ import Processors , skipCached, withCached ) -galleryConf :: String -galleryConf = "gallery.yaml" +defaultGalleryConf :: String +defaultGalleryConf = "gallery.yaml" indexFile :: String indexFile = "index.json" @@ -74,7 +74,6 @@ galleryDirFilter :: CompilerConfig -> [FilePath] -> FSNode -> Bool galleryDirFilter config excludedCanonicalDirs = (not . isHidden) &&& (not . isExcludedDir) - &&& (not . matchesFile (== galleryConf)) &&& ((matchesDir $ anyPattern $ includedDirectories config) ||| (matchesFile $ anyPattern $ includedFiles config)) &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) ||| @@ -100,10 +99,10 @@ galleryDirFilter config excludedCanonicalDirs = isExcludedDir File{} = False -compileGallery :: FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () -compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = +compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () +compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = do - fullConfig <- readConfig inputGalleryConf + fullConfig <- readConfig $ inputGalleryConf configPath let config = compiler fullConfig inputDir <- readDirectory inputDirPath @@ -123,7 +122,10 @@ compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = writeJSON outputViewerConf $ viewer fullConfig where - inputGalleryConf = inputDirPath galleryConf + inputGalleryConf :: FilePath -> FilePath + inputGalleryConf "" = inputDirPath defaultGalleryConf + inputGalleryConf file = file + outputIndex = outputDirPath indexFile outputViewerConf = outputDirPath viewerConfFile diff --git a/ldgallery.1.md b/ldgallery.1.md index a5d0e4c..e891345 100644 --- a/ldgallery.1.md +++ b/ldgallery.1.md @@ -33,6 +33,10 @@ Available options are: Must be distinct from the source directory. Defaults to ./out. +-g, \--gallery-config _FILE_ +: Gallery configuration file. + Defaults to $input-dir/gallery.yaml. + -r, \--rebuild-all : Invalidate cache and recompile everything. -- cgit v1.2.3