aboutsummaryrefslogtreecommitdiff
path: root/compiler/src
diff options
context:
space:
mode:
authorpacien2020-02-22 14:53:03 +0100
committerpacien2020-02-23 22:49:16 +0100
commite42f4e864bac21ed3b19d1869df2cdd4f8c3433c (patch)
tree1d9a22c75da88581f904c91d6492c746932c6927 /compiler/src
parentce0b7ec230703d239b3d77e09352c0b1d515d8f5 (diff)
downloadldgallery-e42f4e864bac21ed3b19d1869df2cdd4f8c3433c.tar.gz
compiler: flatten gallery config
GitHub: closes #129
Diffstat (limited to 'compiler/src')
-rw-r--r--compiler/src/Compiler.hs7
-rw-r--r--compiler/src/Config.hs45
2 files changed, 26 insertions, 26 deletions
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index bb0ee97..73ac8a4 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -70,7 +70,7 @@ writeJSON outputPath object =
70 ensureParentDir JSON.encodeFile outputPath object 70 ensureParentDir JSON.encodeFile outputPath object
71 71
72 72
73galleryDirFilter :: CompilerConfig -> [FilePath] -> FSNode -> Bool 73galleryDirFilter :: GalleryConfig -> [FilePath] -> FSNode -> Bool
74galleryDirFilter config excludedCanonicalDirs = 74galleryDirFilter config excludedCanonicalDirs =
75 (not . isHidden) 75 (not . isHidden)
76 &&& (not . isExcludedDir) 76 &&& (not . isExcludedDir)
@@ -102,8 +102,7 @@ galleryDirFilter config excludedCanonicalDirs =
102compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () 102compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO ()
103compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = 103compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput =
104 do 104 do
105 fullConfig <- readConfig $ inputGalleryConf configPath 105 config <- readConfig $ inputGalleryConf configPath
106 let config = compiler fullConfig
107 106
108 inputDir <- readDirectory inputDirPath 107 inputDir <- readDirectory inputDirPath
109 excludedCanonicalDirs <- mapM canonicalizePath excludedDirs 108 excludedCanonicalDirs <- mapM canonicalizePath excludedDirs
@@ -119,7 +118,7 @@ compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cle
119 118
120 when cleanOutput $ galleryCleanupResourceDir resources outputDirPath 119 when cleanOutput $ galleryCleanupResourceDir resources outputDirPath
121 writeJSON outputIndex resources 120 writeJSON outputIndex resources
122 writeJSON outputViewerConf $ viewer fullConfig 121 writeJSON outputViewerConf $ viewerConfig config
123 122
124 where 123 where
125 inputGalleryConf :: FilePath -> FilePath 124 inputGalleryConf :: FilePath -> FilePath
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs
index bf5a28e..5f1806d 100644
--- a/compiler/src/Config.hs
+++ b/compiler/src/Config.hs
@@ -17,11 +17,10 @@
17-- along with this program. If not, see <https://www.gnu.org/licenses/>. 17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18 18
19module Config 19module Config
20 ( GalleryConfig(..) 20 ( GalleryConfig(..), readConfig
21 , CompilerConfig(..) 21 , ViewerConfig(..), viewerConfig
22 , TagsFromDirectoriesConfig(..) 22 , TagsFromDirectoriesConfig(..)
23 , Resolution(..) 23 , Resolution(..)
24 , readConfig
25 ) where 24 ) where
26 25
27 26
@@ -39,7 +38,18 @@ data Resolution = Resolution
39 } deriving (Generic, Show, ToJSON, FromJSON) 38 } deriving (Generic, Show, ToJSON, FromJSON)
40 39
41 40
42data CompilerConfig = CompilerConfig 41data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig
42 { fromParents :: Int
43 , prefix :: String
44 } deriving (Generic, Show)
45
46instance FromJSON TagsFromDirectoriesConfig where
47 parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig
48 <$> v .:? "fromParents" .!= 0
49 <*> v .:? "prefix" .!= ""
50
51
52data GalleryConfig = GalleryConfig
43 { includedDirectories :: [String] 53 { includedDirectories :: [String]
44 , excludedDirectories :: [String] 54 , excludedDirectories :: [String]
45 , includedFiles :: [String] 55 , includedFiles :: [String]
@@ -49,8 +59,8 @@ data CompilerConfig = CompilerConfig
49 , pictureMaxResolution :: Maybe Resolution 59 , pictureMaxResolution :: Maybe Resolution
50 } deriving (Generic, Show) 60 } deriving (Generic, Show)
51 61
52instance FromJSON CompilerConfig where 62instance FromJSON GalleryConfig where
53 parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig 63 parseJSON = withObject "GalleryConfig" $ \v -> GalleryConfig
54 <$> v .:? "includedDirectories" .!= ["*"] 64 <$> v .:? "includedDirectories" .!= ["*"]
55 <*> v .:? "excludedDirectories" .!= [] 65 <*> v .:? "excludedDirectories" .!= []
56 <*> v .:? "includedFiles" .!= ["*"] 66 <*> v .:? "includedFiles" .!= ["*"]
@@ -59,22 +69,13 @@ instance FromJSON CompilerConfig where
59 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300) 69 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300)
60 <*> v .:? "pictureMaxResolution" 70 <*> v .:? "pictureMaxResolution"
61 71
62 72readConfig :: FileName -> IO GalleryConfig
63data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig 73readConfig = decodeYamlFile
64 { fromParents :: Int
65 , prefix :: String
66 } deriving (Generic, Show)
67
68instance FromJSON TagsFromDirectoriesConfig where
69 parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig
70 <$> v .:? "fromParents" .!= 0
71 <*> v .:? "prefix" .!= ""
72 74
73 75
74data GalleryConfig = GalleryConfig 76data ViewerConfig = ViewerConfig
75 { compiler :: CompilerConfig 77 { -- TODO: add viewer config keys (tag groups...)
76 , viewer :: JSON.Object 78 } deriving (Generic, ToJSON, Show)
77 } deriving (Generic, FromJSON, Show)
78 79
79readConfig :: FileName -> IO GalleryConfig 80viewerConfig :: GalleryConfig -> ViewerConfig
80readConfig = decodeYamlFile 81viewerConfig _ = ViewerConfig -- TODO