allow separate title in gallery e.g. to avoid spoilers

This commit is contained in:
Rhiannon Morris 2022-02-27 23:48:35 +01:00
parent ca647f33c1
commit 32f308d7f6
2 changed files with 26 additions and 21 deletions

View File

@ -13,6 +13,7 @@ import qualified Data.HashMap.Strict as HashMap
import Data.HashSet (HashSet) import Data.HashSet (HashSet)
import qualified Data.HashSet as HashSet import qualified Data.HashSet as HashSet
import Data.List (intersperse, groupBy, sortBy, sortOn) import Data.List (intersperse, groupBy, sortBy, sortOn)
import Data.Maybe
import qualified Data.Text.Lazy as Lazy import qualified Data.Text.Lazy as Lazy
import System.FilePath (takeDirectory, joinPath, splitPath) import System.FilePath (takeDirectory, joinPath, splitPath)
import GHC.Exts (Down (..), the) import GHC.Exts (Down (..), the)
@ -145,7 +146,7 @@ makeYearItems nsfw year infos = [b|@0
year' = show year & foldMap \c -> [b|<span class=y>$c</span>|] year' = show year & foldMap \c -> [b|<span class=y>$c</span>|]
makeItem :: Bool -> FilePath -> Info -> Builder makeItem :: Bool -> FilePath -> Info -> Builder
makeItem nsfw file info@(Info {title, bg}) = [b|@0 makeItem nsfw file info@(Info {bg}) = [b|@0
<li class="item post$nsfw'" data-date="$date'" data-year=$year' <li class="item post$nsfw'" data-date="$date'" data-year=$year'
data-updated="$updated'" data-updated="$updated'"
data-tags="$tags'"> data-tags="$tags'">
@ -160,6 +161,7 @@ makeItem nsfw file info@(Info {title, bg}) = [b|@0
</figure> </figure>
|] |]
where where
title = fromMaybe (#title info) $ #galleryTitle info
dir = takeDirectory file dir = takeDirectory file
thumb = getThumb dir info thumb = getThumb dir info
nsfw' = if nsfw && #anyNsfw info then [b| nsfw|] else "" nsfw' = if nsfw && #anyNsfw info then [b| nsfw|] else ""

View File

@ -39,28 +39,29 @@ import Data.Bifunctor (second)
data Info = data Info =
Info { Info {
date :: !Date, date :: !Date,
-- | extra sort key after date -- | extra sort key after date
-- e.g. multiple things on the same day might have a,b,c in @sortEx@ to -- e.g. multiple things on the same day might have a,b,c in @sortEx@ to
-- put them in the right order in the gallery -- put them in the right order in the gallery
sortEx :: !Text, sortEx :: !Text,
updates :: ![Update], updates :: ![Update],
-- | if false, don't show updated emblem even if @updates@ is non-empty -- | if false, don't show updated emblem even if @updates@ is non-empty
showUpdated :: !Bool, showUpdated :: !Bool,
-- | hide from gallery view -- | hide from gallery view
unlisted :: !Bool, unlisted :: !Bool,
title :: !Text, title :: !Text,
artist :: !(Maybe Artist), -- nothing = me, obv galleryTitle :: !(Maybe Text),
nsfwOnly :: !Bool, artist :: !(Maybe Artist), -- nothing = me, obv
tags :: ![Text], nsfwOnly :: !Bool,
nsfwTags :: ![Text], tags :: ![Text],
desc :: !Desc, nsfwTags :: ![Text],
nsfwDesc :: !Desc, desc :: !Desc,
bg :: !(Maybe Text), nsfwDesc :: !Desc,
images :: !Images, bg :: !(Maybe Text),
thumb' :: !(Maybe FilePath), images :: !Images,
links :: ![Link], thumb' :: !(Maybe FilePath),
extras :: ![FilePath] links :: ![Link],
extras :: ![FilePath]
} }
deriving (Eq, Show) deriving (Eq, Show)
@ -257,15 +258,17 @@ checkKeys mapping wanted = do
instance FromYAML Info where instance FromYAML Info where
parseYAML = YAML.withMap "info" \m -> do parseYAML = YAML.withMap "info" \m -> do
checkKeys m ["date", "sort", "updates", "show-updated", "unlisted", "title", checkKeys m ["date", "sort", "updates", "show-updated", "unlisted",
"artist", "nsfw-only", "tags", "nsfw-tags", "desc", "gallery-title", "title", "artist", "nsfw-only", "tags",
"nsfw-desc", "bg", "images", "thumb", "links", "extras"] "nsfw-tags", "desc", "nsfw-desc", "bg", "images", "thumb",
"links", "extras"]
Info <$> m .: "date" Info <$> m .: "date"
<*> m .:? "sort" .!= "" <*> m .:? "sort" .!= ""
<*> (m .:? "updates" >>= updateList) <*> (m .:? "updates" >>= updateList)
<*> m .:? "show-updated" .!= True <*> m .:? "show-updated" .!= True
<*> m .:? "unlisted" .!= False <*> m .:? "unlisted" .!= False
<*> m .: "title" <*> m .: "title"
<*> m .:? "gallery-title"
<*> m .:? "artist" <*> m .:? "artist"
<*> m .:? "nsfw-only" .!= False <*> m .:? "nsfw-only" .!= False
<*> m .:? "tags" .!= [] <*> m .:? "tags" .!= []