some reformatting

This commit is contained in:
Rhiannon Morris 2020-08-01 03:02:26 +02:00
parent 653adfe5fc
commit aef07f0f6f
1 changed files with 13 additions and 13 deletions

View File

@ -182,30 +182,31 @@ instance FromYAML NsfwFilter where
parseYAML = YAML.withStr "nsfw filter" readNsfwFilter
data ArtistFilter = Me | NotMe | AllW deriving (Eq, Show)
data ArtistFilter = Me | NotMe | AllA deriving (Eq, Show)
readArtistFilter :: (IsString str, Eq str, Alternative f)
=> str -> f ArtistFilter
readArtistFilter "me" = pure Me
readArtistFilter "not-me" = pure NotMe
readArtistFilter "all" = pure AllW
readArtistFilter "all" = pure AllA
readArtistFilter _ = empty
matchArtist :: ArtistFilter -> Info -> Bool
matchArtist Me = #mine
matchArtist NotMe = #notMine
matchArtist AllW = const True
matchArtist AllA = const True
noFilters :: GalleryFilters
noFilters =
GalleryFilters {nsfw = AllN, artist = AllW, require = [], exclude = []}
GalleryFilters {nsfw = AllN, artist = AllA, require = [], exclude = []}
matchFilters :: GalleryFilters -> Info -> Bool
matchFilters (GalleryFilters {nsfw, artist, require, exclude}) i =
matchNsfw nsfw i && matchArtist artist i &&
all (\t -> HashSet.member t tags) require &&
all (\t -> not $ HashSet.member t tags) exclude
where tags = HashSet.fromList $ #tags i
all ( tags) require && all ( tags) exclude
where
tags = HashSet.fromList $ #tags i
() = HashSet.member; x xs = not $ x xs
instance FromYAML GalleryInfo where
@ -218,7 +219,7 @@ instance FromYAML GalleryInfo where
instance FromYAML GalleryFilters where
parseYAML = YAML.withMap "gallery filters" \m ->
GalleryFilters <$> m .:? "nsfw" .!= AllN
<*> m .:? "artist" .!= AllW
<*> m .:? "artist" .!= AllA
<*> m .:? "require" .!= []
<*> m .:? "exclude" .!= []
@ -246,11 +247,10 @@ instance FromYAML IndexInfo where
data Pair a b = Pair !a !b
instance (FromYAML a, FromYAML b) => FromYAML (Pair a b) where
parseYAML =
YAML.withMap "single-pair map" \m ->
case Map.toList m of
[(a, b)] -> Pair <$> parseYAML a <*> parseYAML b
_ -> fail "expected exactly one pair"
parseYAML = YAML.withMap "single-pair map" \m ->
case Map.toList m of
[(a, b)] -> Pair <$> parseYAML a <*> parseYAML b
_ -> fail "expected exactly one pair"
instance FromYAML Day where