diff options
Diffstat (limited to 'compiler/src/Resource.hs')
-rw-r--r-- | compiler/src/Resource.hs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index 29906b7..79fe354 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs | |||
@@ -30,8 +30,8 @@ import Data.Char (toLower) | |||
30 | import Data.Maybe (mapMaybe, fromMaybe) | 30 | import Data.Maybe (mapMaybe, fromMaybe) |
31 | import Data.Function ((&)) | 31 | import Data.Function ((&)) |
32 | import qualified Data.Set as Set | 32 | import qualified Data.Set as Set |
33 | import Data.Time.Clock (UTCTime) | ||
33 | import Data.Time.LocalTime (ZonedTime, utc, utcToZonedTime, zonedTimeToUTC) | 34 | import Data.Time.LocalTime (ZonedTime, utc, utcToZonedTime, zonedTimeToUTC) |
34 | import System.Directory (getModificationTime) | ||
35 | import Safe.Foldable (maximumByMay) | 35 | import Safe.Foldable (maximumByMay) |
36 | 36 | ||
37 | import GHC.Generics (Generic) | 37 | import GHC.Generics (Generic) |
@@ -102,14 +102,13 @@ buildGalleryTree processItem processThumbnail tagsFromDirectories galleryName in | |||
102 | mkGalleryItem (Just galleryName) (Path []) inputTree | 102 | mkGalleryItem (Just galleryName) (Path []) inputTree |
103 | where | 103 | where |
104 | mkGalleryItem :: Maybe String -> Path -> InputTree -> IO GalleryItem | 104 | mkGalleryItem :: Maybe String -> Path -> InputTree -> IO GalleryItem |
105 | mkGalleryItem _ parents InputFile{path, sidecar} = | 105 | mkGalleryItem _ parents InputFile{path, modTime, sidecar} = |
106 | do | 106 | do |
107 | properties <- processItem path | 107 | properties <- processItem path |
108 | processedThumbnail <- processThumbnail path | 108 | processedThumbnail <- processThumbnail path |
109 | fileModTime <- lastModTime path | ||
110 | return GalleryItem | 109 | return GalleryItem |
111 | { title = itemTitle | 110 | { title = itemTitle |
112 | , datetime = fromMaybe fileModTime $ Input.datetime sidecar | 111 | , datetime = fromMaybe (toZonedTime modTime) (Input.datetime sidecar) |
113 | , description = optMeta description "" | 112 | , description = optMeta description "" |
114 | , tags = (optMeta tags []) ++ implicitParentTags parents | 113 | , tags = (optMeta tags []) ++ implicitParentTags parents |
115 | , path = parents </ itemTitle | 114 | , path = parents </ itemTitle |
@@ -122,14 +121,13 @@ buildGalleryTree processItem processThumbnail tagsFromDirectories galleryName in | |||
122 | optMeta :: (Sidecar -> Maybe a) -> a -> a | 121 | optMeta :: (Sidecar -> Maybe a) -> a -> a |
123 | optMeta get fallback = fromMaybe fallback $ get sidecar | 122 | optMeta get fallback = fromMaybe fallback $ get sidecar |
124 | 123 | ||
125 | mkGalleryItem rootTitle parents InputDir{path, dirThumbnailPath, items} = | 124 | mkGalleryItem rootTitle parents InputDir{path, modTime, dirThumbnailPath, items} = |
126 | do | 125 | do |
127 | processedThumbnail <- maybeThumbnail dirThumbnailPath | 126 | processedThumbnail <- maybeThumbnail dirThumbnailPath |
128 | processedItems <- parallel $ map (mkGalleryItem Nothing itemPath) items | 127 | processedItems <- parallel $ map (mkGalleryItem Nothing itemPath) items |
129 | dirModTime <- lastModTime path | ||
130 | return GalleryItem | 128 | return GalleryItem |
131 | { title = itemTitle | 129 | { title = itemTitle |
132 | , datetime = fromMaybe dirModTime $ mostRecentChildModTime processedItems | 130 | , datetime = fromMaybe (toZonedTime modTime) (mostRecentChildModTime processedItems) |
133 | , description = "" | 131 | , description = "" |
134 | , tags = (aggregateChildTags processedItems) ++ implicitParentTags parents | 132 | , tags = (aggregateChildTags processedItems) ++ implicitParentTags parents |
135 | , path = itemPath | 133 | , path = itemPath |
@@ -162,11 +160,8 @@ buildGalleryTree processItem processThumbnail tagsFromDirectories galleryName in | |||
162 | implicitParentTags :: Path -> [Tag] | 160 | implicitParentTags :: Path -> [Tag] |
163 | implicitParentTags (Path elements) = take tagsFromDirectories elements | 161 | implicitParentTags (Path elements) = take tagsFromDirectories elements |
164 | 162 | ||
165 | lastModTime :: Path -> IO ZonedTime | 163 | toZonedTime :: UTCTime -> ZonedTime |
166 | lastModTime path = | 164 | toZonedTime = utcToZonedTime utc |
167 | localPath path | ||
168 | & getModificationTime | ||
169 | >>= return . utcToZonedTime utc | ||
170 | 165 | ||
171 | 166 | ||
172 | flattenGalleryTree :: GalleryItem -> [GalleryItem] | 167 | flattenGalleryTree :: GalleryItem -> [GalleryItem] |