support initially-hidden tags

This commit is contained in:
Rhiannon Morris 2020-08-04 02:27:19 +02:00
parent 28fc9db3e0
commit e8bd20c896
3 changed files with 26 additions and 13 deletions

View file

@ -13,6 +13,8 @@ import Records
import Control.Applicative
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)
@ -175,7 +177,8 @@ data GalleryInfo =
title :: !Text,
desc :: !Text,
prefix :: !FilePath,
filters :: !GalleryFilters
filters :: !GalleryFilters,
hidden :: !(HashSet Text) -- ^ tags to initially hide
}
deriving (Eq, Show)
@ -183,7 +186,7 @@ data GalleryFilters =
GalleryFilters {
nsfw :: !NsfwFilter,
artist :: !ArtistFilter,
require, exclude :: ![Text]
require, exclude :: !(HashSet Text)
}
deriving (Eq, Show)
@ -225,10 +228,9 @@ noFilters =
matchFilters :: GalleryFilters -> Info -> Bool
matchFilters (GalleryFilters {nsfw, artist, require, exclude}) i =
matchNsfw nsfw i && matchArtist artist i &&
all ( tags) require && all ( tags) exclude
where
tags = HashSet.fromList $ #tags i
() = HashSet.member; x xs = not $ x xs
all (\t -> HashSet.member t tags) require &&
all (\t -> not $ HashSet.member t tags) exclude
where tags = HashSet.fromList $ #tags i
instance FromYAML GalleryInfo where
@ -237,6 +239,7 @@ instance FromYAML GalleryInfo where
<*> m .: "desc"
<*> m .: "prefix"
<*> m .:? "filters" .!= noFilters
<*> m .:? "hidden" .!= mempty
instance FromYAML GalleryFilters where
parseYAML = YAML.withMap "gallery filters" \m ->
@ -283,3 +286,6 @@ instance FromYAML Day where
instance {-# OVERLAPPING #-} FromYAML String where
parseYAML y = Text.unpack <$> parseYAML y
instance (FromYAML a, Eq a, Hashable a) => FromYAML (HashSet a) where
parseYAML y = HashSet.fromList <$> parseYAML y