diff options
author | Notkea | 2020-02-02 20:39:36 +0100 |
---|---|---|
committer | GitHub | 2020-02-02 20:39:36 +0100 |
commit | bd7b62e97ac3fc89be4df9f3bb15af6b3e6c2724 (patch) | |
tree | eb664b38fefc4a8088ae5c10366f52542e021ff5 /compiler/src/Resource.hs | |
parent | ce2f0262768bc3d56dd9a776a075c6ccf10a7ae3 (diff) | |
parent | 73e2dc5b39a5cd12c52b99ee076c1a1ad86a2ace (diff) | |
download | ldgallery-bd7b62e97ac3fc89be4df9f3bb15af6b3e6c2724.tar.gz |
Merge pull request #74 from pacien/feature-thumbnail-resolution-index
Add thumbnail size to index
Diffstat (limited to 'compiler/src/Resource.hs')
-rw-r--r-- | compiler/src/Resource.hs | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index 599509e..400e18a 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | module Resource | 19 | module Resource |
20 | ( ItemProcessor, ThumbnailProcessor | 20 | ( ItemProcessor, ThumbnailProcessor |
21 | , GalleryItem(..), GalleryItemProps(..), Resolution(..), Resource(..) | 21 | , GalleryItem(..), GalleryItemProps(..), Resolution(..), Resource(..), Thumbnail(..) |
22 | , buildGalleryTree, galleryCleanupResourceDir | 22 | , buildGalleryTree, galleryCleanupResourceDir |
23 | ) where | 23 | ) where |
24 | 24 | ||
@@ -90,13 +90,23 @@ instance ToJSON GalleryItemProps where | |||
90 | toEncoding = genericToEncoding encodingOptions | 90 | toEncoding = genericToEncoding encodingOptions |
91 | 91 | ||
92 | 92 | ||
93 | data Thumbnail = Thumbnail | ||
94 | { resource :: Resource | ||
95 | , resolution :: Resolution | ||
96 | } deriving (Generic, Show) | ||
97 | |||
98 | instance ToJSON Thumbnail where | ||
99 | toJSON = genericToJSON encodingOptions | ||
100 | toEncoding = genericToEncoding encodingOptions | ||
101 | |||
102 | |||
93 | data GalleryItem = GalleryItem | 103 | data GalleryItem = GalleryItem |
94 | { title :: String | 104 | { title :: String |
95 | , datetime :: ZonedTime | 105 | , datetime :: ZonedTime |
96 | , description :: String | 106 | , description :: String |
97 | , tags :: [Tag] | 107 | , tags :: [Tag] |
98 | , path :: Path | 108 | , path :: Path |
99 | , thumbnail :: Maybe Resource | 109 | , thumbnail :: Maybe Thumbnail |
100 | , properties :: GalleryItemProps | 110 | , properties :: GalleryItemProps |
101 | } deriving (Generic, Show) | 111 | } deriving (Generic, Show) |
102 | 112 | ||
@@ -106,7 +116,7 @@ instance ToJSON GalleryItem where | |||
106 | 116 | ||
107 | 117 | ||
108 | type ItemProcessor = Path -> IO GalleryItemProps | 118 | type ItemProcessor = Path -> IO GalleryItemProps |
109 | type ThumbnailProcessor = Path -> IO (Maybe Resource) | 119 | type ThumbnailProcessor = Path -> IO (Maybe Thumbnail) |
110 | 120 | ||
111 | 121 | ||
112 | buildGalleryTree :: | 122 | buildGalleryTree :: |
@@ -150,7 +160,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirectories galleryName in | |||
150 | subItemsParents :: [String] | 160 | subItemsParents :: [String] |
151 | subItemsParents = (maybeToList $ fileName path) ++ parentTitles | 161 | subItemsParents = (maybeToList $ fileName path) ++ parentTitles |
152 | 162 | ||
153 | maybeThumbnail :: Maybe Path -> IO (Maybe Resource) | 163 | maybeThumbnail :: Maybe Path -> IO (Maybe Thumbnail) |
154 | maybeThumbnail Nothing = return Nothing | 164 | maybeThumbnail Nothing = return Nothing |
155 | maybeThumbnail (Just thumbnailPath) = processThumbnail thumbnailPath | 165 | maybeThumbnail (Just thumbnailPath) = processThumbnail thumbnailPath |
156 | 166 | ||
@@ -197,10 +207,16 @@ galleryOutputDiff resources ref = | |||
197 | 207 | ||
198 | resPath :: GalleryItemProps -> Maybe Path | 208 | resPath :: GalleryItemProps -> Maybe Path |
199 | resPath Directory{} = Nothing | 209 | resPath Directory{} = Nothing |
200 | resPath resourceProps = Just (resourcePath $ resource resourceProps) | 210 | resPath resourceProps = |
211 | Just | ||
212 | $ resourcePath | ||
213 | $ (resource :: (GalleryItemProps -> Resource)) resourceProps | ||
201 | 214 | ||
202 | thumbnailPaths :: [GalleryItem] -> [Path] | 215 | thumbnailPaths :: [GalleryItem] -> [Path] |
203 | thumbnailPaths = (map resourcePath) . (mapMaybe thumbnail) | 216 | thumbnailPaths = |
217 | map resourcePath | ||
218 | . map (resource :: (Thumbnail -> Resource)) | ||
219 | . mapMaybe thumbnail | ||
204 | 220 | ||
205 | (\\) :: [Path] -> [Path] -> [Path] | 221 | (\\) :: [Path] -> [Path] -> [Path] |
206 | a \\ b = minusOn orderedForm (sortOn orderedForm a) (sortOn orderedForm b) | 222 | a \\ b = minusOn orderedForm (sortOn orderedForm a) (sortOn orderedForm b) |