some reformatting

This commit is contained in:
Rhiannon Morris 2020-08-01 03:02:26 +02:00
parent 653adfe5fc
commit aef07f0f6f

View file

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