From d360121efd8c7c344d56e8db2e77ecb867ef76a9 Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Wed, 15 Jul 2020 20:07:51 +0200 Subject: [PATCH] make #thumb smarter --- make-pages/Depend.hs | 5 +---- make-pages/Info.hs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/make-pages/Depend.hs b/make-pages/Depend.hs index 91b0fe0..ed04f0a 100644 --- a/make-pages/Depend.hs +++ b/make-pages/Depend.hs @@ -26,10 +26,7 @@ dependSingle' yaml info build nsfw = thumbnail :: Info -> FilePath -thumbnail (Info {thumb = Just t}) = t -thumbnail (Info {images}) - | Just i <- find #sfw images = #path i - | otherwise = error "no thumbnail or sfw images" +thumbnail = fromMaybe (error "no thumbnail or sfw images") . #thumb addSuffix :: String -> FilePath -> FilePath addSuffix suf path = diff --git a/make-pages/Info.hs b/make-pages/Info.hs index f2a158c..ebd44f6 100644 --- a/make-pages/Info.hs +++ b/make-pages/Info.hs @@ -7,13 +7,15 @@ where import Records -import Data.YAML (FromYAML (..), (.:), (.:?), (.!=)) -import qualified Data.YAML as YAML -import Data.Time.Calendar (Day (..)) +import Control.Applicative +import Data.Foldable (find) +import qualified Data.Map.Strict as Map +import Data.Maybe (isJust, isNothing) import Data.Text (Text) import qualified Data.Text as Text -import qualified Data.Map.Strict as Map -import Control.Applicative +import Data.Time.Calendar (Day (..)) +import Data.YAML (FromYAML (..), (.:), (.:?), (.!=)) +import qualified Data.YAML as YAML import Text.Read (readMaybe) @@ -27,7 +29,7 @@ data Info = nsfwTags :: ![Text], description :: !(Maybe Text), images :: ![Image], - thumb :: !(Maybe FilePath), + thumb' :: !(Maybe FilePath), links :: ![Link] } deriving (Eq, Show) @@ -60,6 +62,12 @@ instance HasField "sfw" Info Bool where getField = not . #nsfw instance HasField "sfw" Image Bool where getField = not . #nsfw instance HasField "sfw" Link Bool where getField = not . #nsfw +instance HasField "thumb" Info (Maybe FilePath) where + getField (Info {thumb', images}) = thumb' <|> #path <$> find #sfw images + +instance HasField "mine" Info Bool where getField = isNothing . #artist +instance HasField "notMine" Info Bool where getField = isJust . #artist + instance FromYAML Info where parseYAML = YAML.withMap "info" \m ->