aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Resource.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Resource.hs')
-rw-r--r--compiler/src/Resource.hs38
1 files changed, 24 insertions, 14 deletions
diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs
index fa139e0..6b4b44c 100644
--- a/compiler/src/Resource.hs
+++ b/compiler/src/Resource.hs
@@ -17,9 +17,15 @@
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 Resource 19module Resource
20 ( ItemProcessor, ThumbnailProcessor 20 ( ItemProcessor
21 , GalleryItem(..), GalleryItemProps(..), Resolution(..), Resource(..), Thumbnail(..) 21 , GalleryItem(..)
22 , buildGalleryTree, galleryCleanupResourceDir 22 , GalleryItemProps(..)
23 , Resolution(..)
24 , Resource(..)
25 , Thumbnail(..)
26 , buildGalleryTree
27 , galleryCleanupResourceDir
28 , flattenGalleryTree
23 ) where 29 ) where
24 30
25 31
@@ -115,12 +121,14 @@ data GalleryItem = GalleryItem
115 } deriving (Generic, Show, ToJSON, FromJSON) 121 } deriving (Generic, Show, ToJSON, FromJSON)
116 122
117 123
118type ItemProcessor = Path -> IO GalleryItemProps 124type ItemProcessor a =
119type ThumbnailProcessor = Path -> IO (Maybe Thumbnail) 125 Path -- Item path
126 -> Path -- Resource Path
127 -> IO a
120 128
121 129
122buildGalleryTree :: 130buildGalleryTree ::
123 ItemProcessor -> ThumbnailProcessor -> TagsFromDirectoriesConfig 131 ItemProcessor GalleryItemProps -> ItemProcessor (Maybe Thumbnail) -> TagsFromDirectoriesConfig
124 -> InputTree -> IO GalleryItem 132 -> InputTree -> IO GalleryItem
125buildGalleryTree processItem processThumbnail tagsFromDirsConfig = 133buildGalleryTree processItem processThumbnail tagsFromDirsConfig =
126 mkGalleryItem [] 134 mkGalleryItem []
@@ -128,29 +136,31 @@ buildGalleryTree processItem processThumbnail tagsFromDirsConfig =
128 mkGalleryItem :: [Tag] -> InputTree -> IO GalleryItem 136 mkGalleryItem :: [Tag] -> InputTree -> IO GalleryItem
129 mkGalleryItem inheritedTags InputFile{path, modTime, sidecar} = 137 mkGalleryItem inheritedTags InputFile{path, modTime, sidecar} =
130 do 138 do
131 properties <- processItem path 139 let itemPath = "/" /> path
132 processedThumbnail <- processThumbnail path 140 properties <- processItem itemPath path
141 processedThumbnail <- processThumbnail itemPath path
133 return GalleryItem 142 return GalleryItem
134 { title = Input.title sidecar ?? fileName path ?? "" 143 { title = Input.title sidecar ?? fileName path ?? ""
135 , datetime = Input.datetime sidecar ?? toZonedTime modTime 144 , datetime = Input.datetime sidecar ?? toZonedTime modTime
136 , description = Input.description sidecar ?? "" 145 , description = Input.description sidecar ?? ""
137 , tags = unique ((Input.tags sidecar ?? []) ++ inheritedTags ++ parentDirTags path) 146 , tags = unique ((Input.tags sidecar ?? []) ++ inheritedTags ++ parentDirTags path)
138 , path = "/" /> path 147 , path = itemPath
139 , thumbnail = processedThumbnail 148 , thumbnail = processedThumbnail
140 , properties = properties } 149 , properties = properties }
141 150
142 mkGalleryItem inheritedTags InputDir{path, modTime, sidecar, dirThumbnailPath, items} = 151 mkGalleryItem inheritedTags InputDir{path, modTime, sidecar, dirThumbnailPath, items} =
143 do 152 do
153 let itemPath = "/" /> path
144 let dirTags = (Input.tags sidecar ?? []) ++ inheritedTags 154 let dirTags = (Input.tags sidecar ?? []) ++ inheritedTags
145 processedItems <- parallel $ map (mkGalleryItem dirTags) items 155 processedItems <- parallel $ map (mkGalleryItem dirTags) items
146 processedThumbnail <- maybeThumbnail dirThumbnailPath 156 processedThumbnail <- maybeThumbnail itemPath dirThumbnailPath
147 return GalleryItem 157 return GalleryItem
148 { title = Input.title sidecar ?? fileName path ?? "" 158 { title = Input.title sidecar ?? fileName path ?? ""
149 , datetime = Input.datetime sidecar ?? mostRecentModTime processedItems 159 , datetime = Input.datetime sidecar ?? mostRecentModTime processedItems
150 ?? toZonedTime modTime 160 ?? toZonedTime modTime
151 , description = Input.description sidecar ?? "" 161 , description = Input.description sidecar ?? ""
152 , tags = unique (aggregateTags processedItems ++ parentDirTags path) 162 , tags = unique (aggregateTags processedItems ++ parentDirTags path)
153 , path = "/" /> path 163 , path = itemPath
154 , thumbnail = processedThumbnail 164 , thumbnail = processedThumbnail
155 , properties = Directory processedItems } 165 , properties = Directory processedItems }
156 166
@@ -170,9 +180,9 @@ buildGalleryTree processItem processThumbnail tagsFromDirsConfig =
170 aggregateTags :: [GalleryItem] -> [Tag] 180 aggregateTags :: [GalleryItem] -> [Tag]
171 aggregateTags = concatMap (\item -> tags (item::GalleryItem)) 181 aggregateTags = concatMap (\item -> tags (item::GalleryItem))
172 182
173 maybeThumbnail :: Maybe Path -> IO (Maybe Thumbnail) 183 maybeThumbnail :: Path -> Maybe Path -> IO (Maybe Thumbnail)
174 maybeThumbnail Nothing = return Nothing 184 maybeThumbnail _ Nothing = return Nothing
175 maybeThumbnail (Just thumbnailPath) = processThumbnail thumbnailPath 185 maybeThumbnail itemPath (Just thumbnailPath) = processThumbnail itemPath thumbnailPath
176 186
177 mostRecentModTime :: [GalleryItem] -> Maybe ZonedTime 187 mostRecentModTime :: [GalleryItem] -> Maybe ZonedTime
178 mostRecentModTime = 188 mostRecentModTime =