From 03d39102ba55cda7cbe80fcdeb9b250caaa70bd0 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 6 Jan 2020 10:28:27 +0100 Subject: compiler: properly reject invalid dates in sidecar files GitHub: closes #31 --- compiler/src/Input.hs | 3 ++- compiler/src/Resource.hs | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'compiler/src') diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs index 86d3ec8..85c802e 100644 --- a/compiler/src/Input.hs +++ b/compiler/src/Input.hs @@ -30,6 +30,7 @@ import Data.Function ((&)) import Data.Maybe (catMaybes) import Data.Bool (bool) import Data.List (find) +import Data.Time.LocalTime (ZonedTime) import Data.Yaml (ParseException, decodeFileEither) import Data.Aeson (FromJSON) import System.FilePath (isExtensionOf, dropExtension) @@ -60,7 +61,7 @@ data InputTree = data Sidecar = Sidecar { title :: Maybe String - , date :: Maybe String + , date :: Maybe ZonedTime , description :: Maybe String , tags :: Maybe [String] } deriving (Generic, FromJSON, Show) diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index 207239f..53d61ac 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs @@ -31,7 +31,6 @@ import Data.Maybe (mapMaybe, fromMaybe) import Data.Function ((&)) import qualified Data.Set as Set import Data.Time.LocalTime (ZonedTime, utc, utcToZonedTime, zonedTimeToUTC) -import Data.Time.Format.ISO8601 (iso8601ParseM) import System.Directory (getModificationTime) import Safe.Foldable (maximumByMay) @@ -110,7 +109,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirectories galleryName in fileModTime <- lastModTime path return GalleryItem { title = itemTitle - , date = fromMaybe fileModTime itemDate + , date = fromMaybe fileModTime $ Input.date sidecar , description = optMeta description "" , tags = (optMeta tags []) ++ implicitParentTags parents , path = parents >= iso8601ParseM - optMeta :: (Sidecar -> Maybe a) -> a -> a optMeta get fallback = fromMaybe fallback $ get sidecar -- cgit v1.2.3