diff options
Diffstat (limited to 'compiler/src')
-rw-r--r-- | compiler/src/Compiler.hs | 7 | ||||
-rw-r--r-- | compiler/src/Config.hs | 45 |
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 | ||
73 | galleryDirFilter :: CompilerConfig -> [FilePath] -> FSNode -> Bool | 73 | galleryDirFilter :: GalleryConfig -> [FilePath] -> FSNode -> Bool |
74 | galleryDirFilter config excludedCanonicalDirs = | 74 | galleryDirFilter config excludedCanonicalDirs = |
75 | (not . isHidden) | 75 | (not . isHidden) |
76 | &&& (not . isExcludedDir) | 76 | &&& (not . isExcludedDir) |
@@ -102,8 +102,7 @@ galleryDirFilter config excludedCanonicalDirs = | |||
102 | compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () | 102 | compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () |
103 | compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = | 103 | compileGallery 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 | ||
19 | module Config | 19 | module 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 | ||
42 | data CompilerConfig = CompilerConfig | 41 | data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig |
42 | { fromParents :: Int | ||
43 | , prefix :: String | ||
44 | } deriving (Generic, Show) | ||
45 | |||
46 | instance FromJSON TagsFromDirectoriesConfig where | ||
47 | parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig | ||
48 | <$> v .:? "fromParents" .!= 0 | ||
49 | <*> v .:? "prefix" .!= "" | ||
50 | |||
51 | |||
52 | data 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 | ||
52 | instance FromJSON CompilerConfig where | 62 | instance 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 | 72 | readConfig :: FileName -> IO GalleryConfig | |
63 | data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig | 73 | readConfig = decodeYamlFile |
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 | 74 | ||
73 | 75 | ||
74 | data GalleryConfig = GalleryConfig | 76 | data 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 | ||
79 | readConfig :: FileName -> IO GalleryConfig | 80 | viewerConfig :: GalleryConfig -> ViewerConfig |
80 | readConfig = decodeYamlFile | 81 | viewerConfig _ = ViewerConfig -- TODO |