diff options
-rw-r--r-- | compiler/ldgallery.1.md (renamed from ldgallery.1.md) | 49 | ||||
-rw-r--r-- | compiler/src/Compiler.hs | 7 | ||||
-rw-r--r-- | compiler/src/Config.hs | 45 | ||||
-rw-r--r-- | example/src/gallery.yaml | 34 |
4 files changed, 56 insertions, 79 deletions
diff --git a/ldgallery.1.md b/compiler/ldgallery.1.md index e891345..5524409 100644 --- a/ldgallery.1.md +++ b/compiler/ldgallery.1.md | |||
@@ -110,59 +110,38 @@ tags | |||
110 | 110 | ||
111 | The gallery settings reside in a file named "gallery.yaml" located at the root of the gallery's source directory. | 111 | The gallery settings reside in a file named "gallery.yaml" located at the root of the gallery's source directory. |
112 | 112 | ||
113 | compiler.includedDirectories[] | 113 | includedDirectories[] |
114 | : Glob patterns of directory names to include in the gallery. | 114 | : Glob patterns of directory names to include in the gallery. Defaults to ["*"] (matches all directory names). |
115 | Defaults to ["*"] (matches all directory names). | ||
116 | 115 | ||
117 | compiler.excludedDirectories[] | 116 | excludedDirectories[] |
118 | : Glob patterns of directory names to exclude from the gallery. | 117 | : Glob patterns of directory names to exclude from the gallery. Defaults to [] (none). |
119 | Defaults to [] (none). | ||
120 | 118 | ||
121 | compiler.includedFiles[] | 119 | includedFiles[] |
122 | : Glob patterns of file names to include in the gallery. | 120 | : Glob patterns of file names to include in the gallery. Defaults to ["*"] (matches all file names). |
123 | Defaults to ["*"] (matches all file names). | ||
124 | 121 | ||
125 | compiler.excludedFiles[] | 122 | excludedFiles[] |
126 | : Glob patterns of file names to exclude from the gallery. | 123 | : Glob patterns of file names to exclude from the gallery. Defaults to [] (none). |
127 | Defaults to [] (none). | ||
128 | 124 | ||
129 | compiler.tagsFromDirectories.fromParents | 125 | tagsFromDirectories.fromParents |
130 | : Automatically generate tags from the name of parent directories, | 126 | : Automatically generate tags from the name of parent directories, |
131 | looking up in the hierarchy as far as indicated by this parameter. | 127 | looking up in the hierarchy as far as indicated by this parameter. |
132 | Defaults to 0 (do not generate tags from parent directories). | 128 | Defaults to 0 (do not generate tags from parent directories). |
133 | 129 | ||
134 | compiler.tagsFromDirectories.prefix | 130 | tagsFromDirectories.prefix |
135 | : Prefix to use for tags automatically generated from the parent directories' names. | 131 | : Prefix to use for tags automatically generated from the parent directories' names. |
136 | 132 | ||
137 | compiler.thumbnailMaxResolution.width | 133 | thumbnailMaxResolution.width |
138 | : Maximum width in pixels of the item thumbnails, 400 by default. | 134 | : Maximum width in pixels of the item thumbnails, 400 by default. |
139 | 135 | ||
140 | compiler.thumbnailMaxResolution.height | 136 | thumbnailMaxResolution.height |
141 | : Maximum height in pixels of the item thumbnails, 300 by default. | 137 | : Maximum height in pixels of the item thumbnails, 300 by default. |
142 | 138 | ||
143 | compiler.pictureMaxResolution.width | 139 | pictureMaxResolution.width |
144 | : Maximum width in pixels of the picture items, unlimited by default. | 140 | : Maximum width in pixels of the picture items, unlimited by default. |
145 | 141 | ||
146 | compiler.pictureMaxResolution.height | 142 | pictureMaxResolution.height |
147 | : Maximum height in pixels of the picture items, unlimited by default. | 143 | : Maximum height in pixels of the picture items, unlimited by default. |
148 | 144 | ||
149 | viewer.defaultSearchQuery [TODO] | ||
150 | : Default search query string. | ||
151 | |||
152 | viewer.defaultSortOrder [TODO] | ||
153 | : Default sort order ("alphanumeric", "reverse-alphanumeric", "date", "reverse-date"). | ||
154 | Defaults to "date". | ||
155 | |||
156 | viewer.tagGroups[].tag [TODO] | ||
157 | : Tag prefix defining the tag group. | ||
158 | |||
159 | viewer.tagGroups[].colour [TODO] | ||
160 | : Colour associated to the tag group. | ||
161 | |||
162 | viewer.hiddenTags [TODO] | ||
163 | : List of tags to hide by default. | ||
164 | Items bearing one of those tags will not be displayed until they are being explicitly searched for. | ||
165 | |||
166 | 145 | ||
167 | # SEE ALSO | 146 | # SEE ALSO |
168 | 147 | ||
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 |
diff --git a/example/src/gallery.yaml b/example/src/gallery.yaml index 3408571..b25b657 100644 --- a/example/src/gallery.yaml +++ b/example/src/gallery.yaml | |||
@@ -1,24 +1,22 @@ | |||
1 | compiler: | 1 | # ldgallery example gallery configuration file |
2 | #includedDirectories: ["*"] | ||
3 | #excludedDirectories: [] | ||
4 | 2 | ||
5 | includedFiles: | 3 | #includedDirectories: ["*"] |
6 | - "*.jpg" | 4 | #excludedDirectories: [] |
7 | |||
8 | #excludedFiles: | ||
9 | #- "*.md" | ||
10 | 5 | ||
11 | tagsFromDirectories: | 6 | includedFiles: |
12 | fromParents: 0 # default | 7 | - "*.jpg" |
13 | prefix: "" # default | ||
14 | 8 | ||
15 | thumbnailMaxResolution: | 9 | #excludedFiles: |
16 | width: 400 # default | 10 | # - "*.md" |
17 | height: 300 # default | ||
18 | 11 | ||
19 | pictureMaxResolution: | 12 | tagsFromDirectories: |
20 | width: 1024 | 13 | fromParents: 0 # default |
21 | height: 768 | 14 | prefix: "" # default |
22 | 15 | ||
16 | thumbnailMaxResolution: | ||
17 | width: 400 # default | ||
18 | height: 300 # default | ||