From 74e4a83ac7511086f45d2fa9880b7ae5728020bd Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 25 Feb 2020 20:19:54 +0100 Subject: compiler: add cli arg for output gallery index GitHub: closes #143 --- compiler/app/Main.hs | 8 ++++++++ compiler/ldgallery.1.md | 5 +++++ compiler/src/Compiler.hs | 14 +++++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) (limited to 'compiler') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 404de4b..a4b6ae2 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -39,6 +39,7 @@ data ViewerConfig = ViewerConfig data Options = Options { inputDir :: FilePath , outputDir :: FilePath + , outputIndex :: FilePath , galleryConfig :: FilePath , rebuilAll :: Bool , cleanOutput :: Bool @@ -59,6 +60,12 @@ options = Options &= name "output-dir" &= explicit &= help "Generated gallery output path (default=./out)" + , outputIndex = "" + &= typFile + &= name "x" + &= name "output-index" + &= explicit + &= help "Generated gallery index output path (default=$output-dir/index.json)" , galleryConfig = "" &= typFile &= name "g" @@ -110,6 +117,7 @@ main = (galleryConfig opts) (inputDir opts) (galleryOutputDir opts) + (outputIndex opts) [outputDir opts] (rebuilAll opts) (cleanOutput opts) diff --git a/compiler/ldgallery.1.md b/compiler/ldgallery.1.md index 5524409..fd0355b 100644 --- a/compiler/ldgallery.1.md +++ b/compiler/ldgallery.1.md @@ -33,6 +33,10 @@ Available options are: Must be distinct from the source directory. Defaults to ./out. +-x, \--output-index _FILE_ +: Generated gallery index output path. + Defaults to $output-dir/index.json. + -g, \--gallery-config _FILE_ : Gallery configuration file. Defaults to $input-dir/gallery.yaml. @@ -45,6 +49,7 @@ Available options are: -w, \--with-viewer : Include the static web viewer in the output. + The compiled gallery itself is then placed in $output-dir/gallery. -h, \--help : Display help message. diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 2970102..51f5065 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -51,8 +51,8 @@ import Processors defaultGalleryConf :: String defaultGalleryConf = "gallery.yaml" -indexFile :: String -indexFile = "index.json" +defaultIndexFile :: String +defaultIndexFile = "index.json" itemsDir :: String itemsDir = "items" @@ -103,8 +103,8 @@ galleryDirFilter config excludedCanonicalDirs = isExcludedDir File{} = False -compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () -compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = +compileGallery :: FilePath -> FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () +compileGallery configPath inputDirPath outputDirPath outputIndexPath excludedDirs rebuildAll cleanOutput = do config <- readConfig $ inputGalleryConf configPath @@ -121,13 +121,17 @@ compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cle resources <- galleryBuilder inputTree when cleanOutput $ galleryCleanupResourceDir resources outputDirPath - writeJSON (outputDirPath indexFile) $ GalleryIndex (viewerConfig config) resources + writeJSON (outputGalleryIndex outputIndexPath) $ GalleryIndex (viewerConfig config) resources where inputGalleryConf :: FilePath -> FilePath inputGalleryConf "" = inputDirPath defaultGalleryConf inputGalleryConf file = file + outputGalleryIndex :: FilePath -> FilePath + outputGalleryIndex "" = outputDirPath defaultIndexFile + outputGalleryIndex file = file + itemProcessor config cache = itemFileProcessor (pictureMaxResolution config) cache -- cgit v1.2.3