From c9dc88793119243cfbb02113ea5385006c09d23e Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Fri, 24 Jul 2020 14:17:54 +0200 Subject: [PATCH] add extra nsfw-description field (nsfw pages show both) --- make-pages/Info.hs | 20 +++++++++++--------- make-pages/SinglePage.hs | 15 ++++++++++----- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/make-pages/Info.hs b/make-pages/Info.hs index 06cb07b..4ab64aa 100644 --- a/make-pages/Info.hs +++ b/make-pages/Info.hs @@ -27,15 +27,16 @@ import Text.Read (readMaybe) data Info = Info { - date :: !Day, - title :: !Text, - artist :: !(Maybe Artist), -- nothing = me, obv - tags :: ![Text], - nsfwTags :: ![Text], - description :: !(Maybe Text), - images :: ![Image], - thumb' :: !(Maybe FilePath), - links :: ![Link] + date :: !Day, + title :: !Text, + artist :: !(Maybe Artist), -- nothing = me, obv + tags :: ![Text], + nsfwTags :: ![Text], + description :: !(Maybe Text), + nsfwDescription :: !(Maybe Text), + images :: ![Image], + thumb' :: !(Maybe FilePath), + links :: ![Link] } deriving (Eq, Show) @@ -100,6 +101,7 @@ instance FromYAML Info where <*> m .:? "tags" .!= [] <*> m .:? "nsfw-tags" .!= [] <*> m .:? "description" + <*> m .:? "nsfw-description" <*> (m .: "images" >>= imageList) <*> m .:? "thumb" <*> m .:? "links" .!= [] diff --git a/make-pages/SinglePage.hs b/make-pages/SinglePage.hs index 0dbb7dc..3ecd3e5 100644 --- a/make-pages/SinglePage.hs +++ b/make-pages/SinglePage.hs @@ -6,6 +6,7 @@ import BuilderQQ import Records () import Control.Exception +import Control.Monad import Data.Maybe (fromMaybe) import qualified Data.Text as Strict import qualified Data.Text.Lazy as Lazy @@ -30,7 +31,7 @@ make nsfw dir = toLazyText . make' nsfw dir make' :: Bool -> FilePath -> Info -> Builder make' nsfw dir (Info {date, title, artist, tags, nsfwTags, - description, images, links}) = [b|@0 + description, nsfwDescription, images, links}) = [b|@0 @@ -83,7 +84,7 @@ make' nsfw dir (Info {date, title, artist, tags, nsfwTags, download0 = fromMaybe path0 (#download image0) path0' = pageFile path0 - descSection = ifJust description makeDesc + descSection = makeDesc nsfw description nsfwDescription tagsList = makeTags nsfw tags nsfwTags linksList = extLinks nsfw links @@ -102,15 +103,19 @@ makeArtist (Artist {name, url}) = Just u -> [b|$*name|] Nothing -> [b|$*name|] -makeDesc :: Strict.Text -> Builder -makeDesc desc = [b|@4 +makeDesc :: Bool -> Maybe Strict.Text -> Maybe Strict.Text -> Builder +makeDesc nsfw desc nsfwDesc = [b|@4

about

- $8*desc + $8*desc' + $8*nsfwDesc'
|] + where + desc' = fromMaybe "" desc + nsfwDesc' = fromMaybe "" $ guard nsfw *> nsfwDesc ifJust :: Monoid b => Maybe a -> (a -> b) -> b ifJust x f = maybe mempty f x