From 7dde692101a7e36e0a431aeb864cbf3a0c0e96f8 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 31 Jan 2020 19:43:24 +0100 Subject: compiler: add thumbnail size to index --- compiler/src/Resource.hs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'compiler/src/Resource.hs') diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index c0ef317..33f3cf0 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs @@ -18,7 +18,7 @@ module Resource ( ItemProcessor, ThumbnailProcessor - , GalleryItem(..), GalleryItemProps(..), Resolution(..), Resource(..) + , GalleryItem(..), GalleryItemProps(..), Resolution(..), Resource(..), Thumbnail(..) , buildGalleryTree, galleryCleanupResourceDir ) where @@ -90,13 +90,23 @@ instance ToJSON GalleryItemProps where toEncoding = genericToEncoding encodingOptions +data Thumbnail = Thumbnail + { resource :: Resource + , resolution :: Resolution + } deriving (Generic, Show) + +instance ToJSON Thumbnail where + toJSON = genericToJSON encodingOptions + toEncoding = genericToEncoding encodingOptions + + data GalleryItem = GalleryItem { title :: String , datetime :: ZonedTime , description :: String , tags :: [Tag] , path :: Path - , thumbnail :: Maybe Resource + , thumbnail :: Maybe Thumbnail , properties :: GalleryItemProps } deriving (Generic, Show) @@ -106,7 +116,7 @@ instance ToJSON GalleryItem where type ItemProcessor = Path -> IO GalleryItemProps -type ThumbnailProcessor = Path -> IO (Maybe Resource) +type ThumbnailProcessor = Path -> IO (Maybe Thumbnail) buildGalleryTree :: @@ -150,7 +160,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirectories galleryName in subItemsParents :: [String] subItemsParents = (maybeToList $ fileName path) ++ parentTitles - maybeThumbnail :: Maybe Path -> IO (Maybe Resource) + maybeThumbnail :: Maybe Path -> IO (Maybe Thumbnail) maybeThumbnail Nothing = return Nothing maybeThumbnail (Just thumbnailPath) = processThumbnail thumbnailPath @@ -197,10 +207,16 @@ galleryOutputDiff resources ref = resPath :: GalleryItemProps -> Maybe Path resPath Directory{} = Nothing - resPath resourceProps = Just (resourcePath $ resource resourceProps) + resPath resourceProps = + Just + $ resourcePath + $ (resource :: (GalleryItemProps -> Resource)) resourceProps thumbnailPaths :: [GalleryItem] -> [Path] - thumbnailPaths = (map resourcePath) . (mapMaybe thumbnail) + thumbnailPaths = + map resourcePath + . map (resource :: (Thumbnail -> Resource)) + . mapMaybe thumbnail galleryCleanupResourceDir :: GalleryItem -> FileName -> IO () -- cgit v1.2.3