diff options
author | pacien | 2020-02-17 18:09:20 +0100 |
---|---|---|
committer | pacien | 2020-02-23 22:41:40 +0100 |
commit | 68899f0c1ba4f641c376fda1e51d9694b02b9c5d (patch) | |
tree | d1fb9d413d20583bfa94810582d66b381ba3c8c7 /compiler/src/Config.hs | |
parent | cefb6c102d4f23f02f5fabb934d7e9f60861044e (diff) | |
download | ldgallery-68899f0c1ba4f641c376fda1e51d9694b02b9c5d.tar.gz |
compiler: add a prefix setting for tags generated from parent dirs
GitHub: closes #59
Diffstat (limited to 'compiler/src/Config.hs')
-rw-r--r-- | compiler/src/Config.hs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index 4826f17..bf5a28e 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs | |||
@@ -19,17 +19,24 @@ | |||
19 | module Config | 19 | module Config |
20 | ( GalleryConfig(..) | 20 | ( GalleryConfig(..) |
21 | , CompilerConfig(..) | 21 | , CompilerConfig(..) |
22 | , TagsFromDirectoriesConfig(..) | ||
23 | , Resolution(..) | ||
22 | , readConfig | 24 | , readConfig |
23 | ) where | 25 | ) where |
24 | 26 | ||
25 | 27 | ||
26 | import GHC.Generics (Generic) | 28 | import GHC.Generics (Generic) |
27 | import Data.Aeson (FromJSON, withObject, (.:?), (.!=)) | 29 | import Data.Aeson (ToJSON, FromJSON, withObject, (.:?), (.!=)) |
28 | import qualified Data.Aeson as JSON | 30 | import qualified Data.Aeson as JSON |
29 | 31 | ||
30 | import Files (FileName) | 32 | import Files (FileName) |
31 | import Input (decodeYamlFile) | 33 | import Input (decodeYamlFile) |
32 | import Resource (Resolution(..)) | 34 | |
35 | |||
36 | data Resolution = Resolution | ||
37 | { width :: Int | ||
38 | , height :: Int | ||
39 | } deriving (Generic, Show, ToJSON, FromJSON) | ||
33 | 40 | ||
34 | 41 | ||
35 | data CompilerConfig = CompilerConfig | 42 | data CompilerConfig = CompilerConfig |
@@ -37,7 +44,7 @@ data CompilerConfig = CompilerConfig | |||
37 | , excludedDirectories :: [String] | 44 | , excludedDirectories :: [String] |
38 | , includedFiles :: [String] | 45 | , includedFiles :: [String] |
39 | , excludedFiles :: [String] | 46 | , excludedFiles :: [String] |
40 | , tagsFromDirectories :: Int | 47 | , tagsFromDirectories :: TagsFromDirectoriesConfig |
41 | , thumbnailMaxResolution :: Resolution | 48 | , thumbnailMaxResolution :: Resolution |
42 | , pictureMaxResolution :: Maybe Resolution | 49 | , pictureMaxResolution :: Maybe Resolution |
43 | } deriving (Generic, Show) | 50 | } deriving (Generic, Show) |
@@ -48,11 +55,22 @@ instance FromJSON CompilerConfig where | |||
48 | <*> v .:? "excludedDirectories" .!= [] | 55 | <*> v .:? "excludedDirectories" .!= [] |
49 | <*> v .:? "includedFiles" .!= ["*"] | 56 | <*> v .:? "includedFiles" .!= ["*"] |
50 | <*> v .:? "excludedFiles" .!= [] | 57 | <*> v .:? "excludedFiles" .!= [] |
51 | <*> v .:? "tagsFromDirectories" .!= 0 | 58 | <*> v .:? "tagsFromDirectories" .!= (TagsFromDirectoriesConfig 0 "") |
52 | <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300) | 59 | <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300) |
53 | <*> v .:? "pictureMaxResolution" | 60 | <*> v .:? "pictureMaxResolution" |
54 | 61 | ||
55 | 62 | ||
63 | data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig | ||
64 | { fromParents :: Int | ||
65 | , prefix :: String | ||
66 | } deriving (Generic, Show) | ||
67 | |||
68 | instance FromJSON TagsFromDirectoriesConfig where | ||
69 | parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig | ||
70 | <$> v .:? "fromParents" .!= 0 | ||
71 | <*> v .:? "prefix" .!= "" | ||
72 | |||
73 | |||
56 | data GalleryConfig = GalleryConfig | 74 | data GalleryConfig = GalleryConfig |
57 | { compiler :: CompilerConfig | 75 | { compiler :: CompilerConfig |
58 | , viewer :: JSON.Object | 76 | , viewer :: JSON.Object |