add bg property for displaying transparent images

This commit is contained in:
Rhiannon Morris 2020-08-10 05:42:18 +02:00
parent 1e0b955029
commit 8865b951fa
3 changed files with 12 additions and 4 deletions

View file

@ -122,11 +122,11 @@ makeYearItems nsfw year infos = [b|@4
year' = show year & foldMap \c -> [b|<span class=y>$'c</span>|]
makeItem :: Bool -> FilePath -> Info -> Builder
makeItem nsfw file info@(Info {title}) = [b|@4
makeItem nsfw file info@(Info {title, bg}) = [b|@4
<li class="item post$nsfw'" data-tags="$tags'">
<figure>
<a href="$@dir">
<img src="$@thumb">
<img src="$@thumb"$bgStyle>
</a>
<figcaption>$*title</figcaption>
</figure>
@ -136,3 +136,4 @@ makeItem nsfw file info@(Info {title}) = [b|@4
thumb = maybe (throw $ NoThumb dir) (\t -> dir </> thumbFile t) $ #thumb info
nsfw' = if nsfw && #anyNsfw info then " nsfw" else ""
tags' = fold $ intersperse ";" $ map fromText $ tagsFor nsfw info
bgStyle = ifJust bg \col -> [b| style="background: $*col"|]

View file

@ -39,6 +39,7 @@ data Info =
nsfwTags :: ![Text],
desc :: !(Maybe Text),
nsfwDesc :: !(Maybe Text),
bg :: !(Maybe Text),
images :: ![Image],
thumb' :: !(Maybe FilePath),
links :: ![Link],
@ -125,6 +126,7 @@ instance FromYAML Info where
<*> m .:? "nsfw-tags" .!= []
<*> m .:? "desc"
<*> m .:? "nsfw-desc"
<*> m .:? "bg"
<*> (m .: "images" >>= imageList)
<*> m .:? "thumb"
<*> m .:? "links" .!= []

View file

@ -32,7 +32,7 @@ make :: Bool -- ^ nsfw?
make nsfw dataDir dir info = toLazyText <$> make' nsfw dataDir dir info
make' :: Bool -> FilePath -> FilePath -> Info -> IO Builder
make' nsfw dataDir dir info@(Info {date, title, artist}) = do
make' nsfw dataDir dir info@(Info {date, title, artist, bg}) = do
images <- withSizes (dataDir </> dir) $ imagesFor nsfw info
let undir = joinPath (replicate (length (splitPath dir)) "..")
@ -59,7 +59,11 @@ make' nsfw dataDir dir info@(Info {date, title, artist}) = do
<figcaption id=cw aria-role=button tabindex=0>
<span id=cw-text>cw: <b>$*w</b></span>
</figcaption>
|]
|]
let bgStyle = ifJust bg \col -> [b|@0
<style> #mainfig { background: $*col; } </style>
|]
pure [b|@0
<!DOCTYPE html>
@ -70,6 +74,7 @@ make' nsfw dataDir dir info@(Info {date, title, artist}) = do
<link rel=icon href=/style/niss.svg>
<script src=/script/single.js></script>
$bgStyle
$0.prefetches