From e42f4e864bac21ed3b19d1869df2cdd4f8c3433c Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 22 Feb 2020 14:53:03 +0100 Subject: compiler: flatten gallery config GitHub: closes #129 --- compiler/src/Compiler.hs | 7 +++---- compiler/src/Config.hs | 45 +++++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 26 deletions(-) (limited to 'compiler/src') 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 = ensureParentDir JSON.encodeFile outputPath object -galleryDirFilter :: CompilerConfig -> [FilePath] -> FSNode -> Bool +galleryDirFilter :: GalleryConfig -> [FilePath] -> FSNode -> Bool galleryDirFilter config excludedCanonicalDirs = (not . isHidden) &&& (not . isExcludedDir) @@ -102,8 +102,7 @@ galleryDirFilter config excludedCanonicalDirs = compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = do - fullConfig <- readConfig $ inputGalleryConf configPath - let config = compiler fullConfig + config <- readConfig $ inputGalleryConf configPath inputDir <- readDirectory inputDirPath excludedCanonicalDirs <- mapM canonicalizePath excludedDirs @@ -119,7 +118,7 @@ compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cle when cleanOutput $ galleryCleanupResourceDir resources outputDirPath writeJSON outputIndex resources - writeJSON outputViewerConf $ viewer fullConfig + writeJSON outputViewerConf $ viewerConfig config where 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 @@ -- along with this program. If not, see . module Config - ( GalleryConfig(..) - , CompilerConfig(..) + ( GalleryConfig(..), readConfig + , ViewerConfig(..), viewerConfig , TagsFromDirectoriesConfig(..) , Resolution(..) - , readConfig ) where @@ -39,7 +38,18 @@ data Resolution = Resolution } deriving (Generic, Show, ToJSON, FromJSON) -data CompilerConfig = CompilerConfig +data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig + { fromParents :: Int + , prefix :: String + } deriving (Generic, Show) + +instance FromJSON TagsFromDirectoriesConfig where + parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig + <$> v .:? "fromParents" .!= 0 + <*> v .:? "prefix" .!= "" + + +data GalleryConfig = GalleryConfig { includedDirectories :: [String] , excludedDirectories :: [String] , includedFiles :: [String] @@ -49,8 +59,8 @@ data CompilerConfig = CompilerConfig , pictureMaxResolution :: Maybe Resolution } deriving (Generic, Show) -instance FromJSON CompilerConfig where - parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig +instance FromJSON GalleryConfig where + parseJSON = withObject "GalleryConfig" $ \v -> GalleryConfig <$> v .:? "includedDirectories" .!= ["*"] <*> v .:? "excludedDirectories" .!= [] <*> v .:? "includedFiles" .!= ["*"] @@ -59,22 +69,13 @@ instance FromJSON CompilerConfig where <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300) <*> v .:? "pictureMaxResolution" - -data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig - { fromParents :: Int - , prefix :: String - } deriving (Generic, Show) - -instance FromJSON TagsFromDirectoriesConfig where - parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig - <$> v .:? "fromParents" .!= 0 - <*> v .:? "prefix" .!= "" +readConfig :: FileName -> IO GalleryConfig +readConfig = decodeYamlFile -data GalleryConfig = GalleryConfig - { compiler :: CompilerConfig - , viewer :: JSON.Object - } deriving (Generic, FromJSON, Show) +data ViewerConfig = ViewerConfig + { -- TODO: add viewer config keys (tag groups...) + } deriving (Generic, ToJSON, Show) -readConfig :: FileName -> IO GalleryConfig -readConfig = decodeYamlFile +viewerConfig :: GalleryConfig -> ViewerConfig +viewerConfig _ = ViewerConfig -- TODO -- cgit v1.2.3