diff options
author | pacien | 2020-02-21 15:39:01 +0100 |
---|---|---|
committer | pacien | 2020-02-23 22:42:03 +0100 |
commit | ce0b7ec230703d239b3d77e09352c0b1d515d8f5 (patch) | |
tree | 7aaebf14164df273699ebd3140cd1b8d49e93c7f | |
parent | 68899f0c1ba4f641c376fda1e51d9694b02b9c5d (diff) | |
download | ldgallery-ce0b7ec230703d239b3d77e09352c0b1d515d8f5.tar.gz |
compiler: add gallery config file CLI argument
GitHub: closes #136
-rw-r--r-- | compiler/app/Main.hs | 12 | ||||
-rw-r--r-- | compiler/src/Compiler.hs | 16 | ||||
-rw-r--r-- | 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 | |||
37 | 37 | ||
38 | 38 | ||
39 | data Options = Options | 39 | data Options = Options |
40 | { inputDir :: String | 40 | { inputDir :: FilePath |
41 | , outputDir :: String | 41 | , outputDir :: FilePath |
42 | , galleryConfig :: FilePath | ||
42 | , rebuilAll :: Bool | 43 | , rebuilAll :: Bool |
43 | , cleanOutput :: Bool | 44 | , cleanOutput :: Bool |
44 | , withViewer :: Bool | 45 | , withViewer :: Bool |
@@ -58,6 +59,12 @@ options = Options | |||
58 | &= name "output-dir" | 59 | &= name "output-dir" |
59 | &= explicit | 60 | &= explicit |
60 | &= help "Generated gallery output path (default=./out)" | 61 | &= help "Generated gallery output path (default=./out)" |
62 | , galleryConfig = "" | ||
63 | &= typFile | ||
64 | &= name "g" | ||
65 | &= name "gallery-config" | ||
66 | &= explicit | ||
67 | &= help "Gallery configuration file (default=$input-dir/gallery.yaml)" | ||
61 | , rebuilAll = False | 68 | , rebuilAll = False |
62 | &= name "r" | 69 | &= name "r" |
63 | &= name "rebuild-all" | 70 | &= name "rebuild-all" |
@@ -99,6 +106,7 @@ main = | |||
99 | buildGallery opts = | 106 | buildGallery opts = |
100 | checkDistinctPaths (inputDir opts) (outputDir opts) | 107 | checkDistinctPaths (inputDir opts) (outputDir opts) |
101 | >> compileGallery | 108 | >> compileGallery |
109 | (galleryConfig opts) | ||
102 | (inputDir opts) | 110 | (inputDir opts) |
103 | (galleryOutputDir opts) | 111 | (galleryOutputDir opts) |
104 | [outputDir opts] | 112 | [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 | |||
47 | , skipCached, withCached ) | 47 | , skipCached, withCached ) |
48 | 48 | ||
49 | 49 | ||
50 | galleryConf :: String | 50 | defaultGalleryConf :: String |
51 | galleryConf = "gallery.yaml" | 51 | defaultGalleryConf = "gallery.yaml" |
52 | 52 | ||
53 | indexFile :: String | 53 | indexFile :: String |
54 | indexFile = "index.json" | 54 | indexFile = "index.json" |
@@ -74,7 +74,6 @@ galleryDirFilter :: CompilerConfig -> [FilePath] -> FSNode -> Bool | |||
74 | galleryDirFilter config excludedCanonicalDirs = | 74 | galleryDirFilter config excludedCanonicalDirs = |
75 | (not . isHidden) | 75 | (not . isHidden) |
76 | &&& (not . isExcludedDir) | 76 | &&& (not . isExcludedDir) |
77 | &&& (not . matchesFile (== galleryConf)) | ||
78 | &&& ((matchesDir $ anyPattern $ includedDirectories config) ||| | 77 | &&& ((matchesDir $ anyPattern $ includedDirectories config) ||| |
79 | (matchesFile $ anyPattern $ includedFiles config)) | 78 | (matchesFile $ anyPattern $ includedFiles config)) |
80 | &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) ||| | 79 | &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) ||| |
@@ -100,10 +99,10 @@ galleryDirFilter config excludedCanonicalDirs = | |||
100 | isExcludedDir File{} = False | 99 | isExcludedDir File{} = False |
101 | 100 | ||
102 | 101 | ||
103 | compileGallery :: FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () | 102 | compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () |
104 | compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = | 103 | compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = |
105 | do | 104 | do |
106 | fullConfig <- readConfig inputGalleryConf | 105 | fullConfig <- readConfig $ inputGalleryConf configPath |
107 | let config = compiler fullConfig | 106 | let config = compiler fullConfig |
108 | 107 | ||
109 | inputDir <- readDirectory inputDirPath | 108 | inputDir <- readDirectory inputDirPath |
@@ -123,7 +122,10 @@ compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = | |||
123 | writeJSON outputViewerConf $ viewer fullConfig | 122 | writeJSON outputViewerConf $ viewer fullConfig |
124 | 123 | ||
125 | where | 124 | where |
126 | inputGalleryConf = inputDirPath </> galleryConf | 125 | inputGalleryConf :: FilePath -> FilePath |
126 | inputGalleryConf "" = inputDirPath </> defaultGalleryConf | ||
127 | inputGalleryConf file = file | ||
128 | |||
127 | outputIndex = outputDirPath </> indexFile | 129 | outputIndex = outputDirPath </> indexFile |
128 | outputViewerConf = outputDirPath </> viewerConfFile | 130 | outputViewerConf = outputDirPath </> viewerConfFile |
129 | 131 | ||
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: | |||
33 | Must be distinct from the source directory. | 33 | Must be distinct from the source directory. |
34 | Defaults to ./out. | 34 | Defaults to ./out. |
35 | 35 | ||
36 | -g, \--gallery-config _FILE_ | ||
37 | : Gallery configuration file. | ||
38 | Defaults to $input-dir/gallery.yaml. | ||
39 | |||
36 | -r, \--rebuild-all | 40 | -r, \--rebuild-all |
37 | : Invalidate cache and recompile everything. | 41 | : Invalidate cache and recompile everything. |
38 | 42 | ||