support updates

This commit is contained in:
Rhiannon Morris 2020-09-19 07:51:52 +02:00
parent e296e41b8b
commit 7f91331195
7 changed files with 120 additions and 39 deletions

View file

@ -19,6 +19,7 @@ import Data.Foldable (find)
import Data.Hashable (Hashable)
import Data.HashSet (HashSet)
import qualified Data.HashSet as HashSet
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (isJust, isNothing)
import Data.List (nub)
@ -40,6 +41,7 @@ data Info =
-- e.g. multiple things on the same day might have a,b,c in @sortEx@ to
-- put them in the right order in the gallery
sortEx :: !Text,
updates :: !(Map Day Text),
title :: !Text,
artist :: !(Maybe Artist), -- nothing = me, obv
nsfwOnly :: !Bool,
@ -109,6 +111,11 @@ instance HasField "year" Info Integer where getField = #first . #dmy
instance HasField "month" Info Int where getField = #second . #dmy
instance HasField "day" Info Int where getField = #third . #dmy
instance HasField "latestDate" Info Day where
getField (Info {date, updates}) = maximum (date : Map.keys updates)
instance HasField "updated" Info Bool where getField = not . Map.null . #updates
descFor :: Bool -> Info -> Maybe Text
descFor nsfw (Info {desc, nsfwDesc}) = desc <> (guard nsfw *> nsfwDesc)
@ -122,7 +129,7 @@ linksFor :: Bool -> Info -> [Link]
linksFor nsfw = if nsfw then #links else #sfwLinks
instance Ord Info where
compare = comparing \Info {date, sortEx, title} -> (date, sortEx, title)
compare = comparing \i -> (#latestDate i, #sortEx i, #title i)
newtype NoThumb = NoThumb FilePath
@ -150,7 +157,8 @@ addSuffix suf path =
instance FromYAML Info where
parseYAML = YAML.withMap "info" \m ->
Info <$> m .: "date"
<*> m .:? "sort" .!= ""
<*> m .:? "sort" .!= ""
<*> m .:? "updates" .!= []
<*> m .: "title"
<*> m .:? "artist"
<*> m .:? "nsfw-only" .!= False