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 qualified Data.HashSet as HashSet
import Data.List (intersperse, groupBy, sortBy, sortOn)
import Data.Maybe
import qualified Data.Text.Lazy as Lazy
import System.FilePath (takeDirectory, joinPath, splitPath)
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>|]
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'
data-updated="$updated'"
data-tags="$tags'">
@ -160,6 +161,7 @@ makeItem nsfw file info@(Info {title, bg}) = [b|@0
</figure>
|]
where
title = fromMaybe (#title info) $ #galleryTitle info
dir = takeDirectory file
thumb = getThumb dir info
nsfw' = if nsfw && #anyNsfw info then [b| nsfw|] else ""

View file

@ -50,6 +50,7 @@ data Info =
-- | hide from gallery view
unlisted :: !Bool,
title :: !Text,
galleryTitle :: !(Maybe Text),
artist :: !(Maybe Artist), -- nothing = me, obv
nsfwOnly :: !Bool,
tags :: ![Text],
@ -257,15 +258,17 @@ checkKeys mapping wanted = do
instance FromYAML Info where
parseYAML = YAML.withMap "info" \m -> do
checkKeys m ["date", "sort", "updates", "show-updated", "unlisted", "title",
"artist", "nsfw-only", "tags", "nsfw-tags", "desc",
"nsfw-desc", "bg", "images", "thumb", "links", "extras"]
checkKeys m ["date", "sort", "updates", "show-updated", "unlisted",
"gallery-title", "title", "artist", "nsfw-only", "tags",
"nsfw-tags", "desc", "nsfw-desc", "bg", "images", "thumb",
"links", "extras"]
Info <$> m .: "date"
<*> m .:? "sort" .!= ""
<*> (m .:? "updates" >>= updateList)
<*> m .:? "show-updated" .!= True
<*> m .:? "unlisted" .!= False
<*> m .: "title"
<*> m .:? "gallery-title"
<*> m .:? "artist"
<*> m .:? "nsfw-only" .!= False
<*> m .:? "tags" .!= []