can ignore updates in gallery sort
This commit is contained in:
parent
1a1a2f3be4
commit
5b213f3881
1 changed files with 14 additions and 10 deletions
|
@ -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 =
|
||||
|
|
Loading…
Reference in a new issue