can ignore updates in gallery sort

This commit is contained in:
Rhiannon Morris 2021-04-16 18:02:17 +02:00
parent 1a1a2f3be4
commit 5b213f3881

View file

@ -15,13 +15,14 @@ import Date
import Records
import Control.Applicative
import Control.Monad
import Control.Exception
import Data.Foldable (find)
import Data.Hashable (Hashable)
import Data.HashSet (HashSet)
import qualified Data.HashSet as HashSet
import qualified Data.Map.Strict as Map
import Data.Maybe (isJust, isNothing, fromMaybe)
import Data.Maybe (isJust, isNothing, fromMaybe, mapMaybe)
import Data.List (nub, sortBy)
import Data.Ord (comparing)
import Data.String (IsString)
@ -93,9 +94,10 @@ data Link =
data Update =
Update {
date :: !Date,
desc :: !Text,
nsfw :: !Bool
date :: !Date,
desc :: !Text,
nsfw :: !Bool,
ignoreSort :: !Bool
}
deriving (Eq, Ord, Show)
@ -129,8 +131,9 @@ instance HasField "mine" Info Bool where getField = isNothing . #artist
instance HasField "notMine" Info Bool where getField = isJust . #artist
instance HasField "latestDate" Info (Bool -> Date) where
getField info@(Info {date}) nsfw =
maximum $ date : map #date (updatesFor nsfw info)
getField info@(Info {date=date}) nsfw =
maximum $ date : mapMaybe relDate (updatesFor nsfw info)
where relDate (Update {date, ignoreSort}) = date <$ guard (not ignoreSort)
instance HasField "latestYear" Info (Bool -> Int) where
getField info nsfw = #year $ #latestDate info nsfw
@ -295,11 +298,12 @@ updateList =
date <- parseYAML date'
asDesc date rest <|> asObj date rest
asDesc date = YAML.withStr "desc" \desc ->
pure $ Update {date, desc, nsfw = False}
pure $ Update {date, desc, nsfw = False, ignoreSort = False}
asObj date = YAML.withMap "update info" \m -> do
desc <- m .: "desc"
nsfw <- m .:? "nsfw" .!= False
pure $ Update {date, desc, nsfw}
desc <- m .: "desc"
nsfw <- m .:? "nsfw" .!= False
ignoreSort <- m .:? "ignore-sort" .!= False
pure $ Update {date, desc, nsfw, ignoreSort}
data GalleryInfo =