a lot of stylin and a little scriptin

This commit is contained in:
Rhiannon Morris 2020-07-17 12:29:13 +02:00
parent 3635f04e8f
commit 64e00f83f1
16 changed files with 555 additions and 82 deletions

View file

@ -30,29 +30,38 @@ make nsfw = toLazyText . make' nsfw
make' :: Bool -> Info -> Builder
make' nsfw (Info {date, title, artist, tags, nsfwTags,
description, images, links}) = [b|@0
description, images, background, links}) = [b|@0
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<link rel=stylesheet href=/style/single.css>
$titleTag
<header>
$titleHeader
$artistTag
<h2 class=date>$formattedDate</date>
<h2 class=date>$formattedDate</h2>
$buttonBar
</header>
<script async src=/script/single.js></script>
<main>
<a href="$@path0">
<img id=it src="$@path0'">
</a>
<figure id=mainfig$dataBg>
$warning'
<a id=mainlink href="$@path0">
<img id=mainimg src="$@path0'">
</a>
</figure>
$descSection
<section class=info>
$descSection
$tagsList
$tagsList
$linksList
$linksList
</section>
</main>
<footer>
@ -70,13 +79,21 @@ make' nsfw (Info {date, title, artist, tags, nsfwTags,
formattedDate = formatDate date
buttonBar = makeButtonBar (fromMaybe (Strict.pack path0) title) nsfw images
path0 = #path $ head images
image0 = head images
path0 = #path image0
path0' = pageFile path0
descSection = ifJust description makeDesc
tagsList = makeTags nsfw tags nsfwTags
linksList = extLinks nsfw links
dataBg = ifJust background \bg -> [b| data-bg="$*bg"|]
warning' = ifJust (#warning image0) \w -> [b|@4
<figcaption id=cw>
$*w
</figcaption>
|]
makeArtist :: Artist -> Builder
makeArtist (Artist {name, url}) =
[b|<h2 class=artist>by $artistLink</h2>|]
@ -86,11 +103,13 @@ makeArtist (Artist {name, url}) =
Nothing -> [b|$*name|]
makeDesc :: Strict.Text -> Builder
makeDesc desc = [b|@2
<div class=desc>
<h2>description</h2>
$4*desc
</div>
makeDesc desc = [b|@4
<section class=desc>
<h2>about</h2>
<div>
$8*desc
</div>
</section>
|]
ifJust :: Monoid b => Maybe a -> (a -> b) -> b
@ -106,9 +125,8 @@ makeButtonBar title nsfw allImages =
0 -> throw $ NoEligibleImages title
1 -> ""
_ -> [b|@2
<nav id=variants class=buttonbar>
<h2>alts</h2>
<ul id=variantlist>
<nav class=alts>
<ul id=altlist>
$6.alts
</ul>
</nav>
@ -119,10 +137,11 @@ makeButtonBar title nsfw allImages =
alts = map (uncurry altButton) $ zip [0..] images
altButton :: Int -> Image -> Builder
altButton i (Image {label, path, nsfw}) = [b|@6
altButton i (Image {label, path, nsfw, warning}) = [b|@6
<li$nsfwClass>
<input type=radio$checked id="$idLabel" name=variant
autocomplete=off value="$@path'">
autocomplete=off value="$@path'"
data-link="$@path"$warning'>
<label for="$idLabel">$*label</label>
|]
where
@ -130,6 +149,7 @@ altButton i (Image {label, path, nsfw}) = [b|@6
checked = if i == 0 then " checked" else ""
idLabel = escId label
path' = pageFile path
warning' = ifJust warning \w -> [b| data-warning="$*w"|]
escId :: Strict.Text -> Builder
escId = foldMap esc1 . Strict.unpack where
@ -140,13 +160,13 @@ escId = foldMap esc1 . Strict.unpack where
makeTags :: Bool -> [Strict.Text] -> [Strict.Text] -> Builder
makeTags nsfw sfwTags nsfwTags =
if null tags then "" else [b|@2
<div class=tags>
if null tags then "" else [b|@4
<section class=tags>
<h2>tags</h2>
<ul>
$6.tagList
$8.tagList
</ul>
</div>
</section>
|]
where
tagList = map makeTag tags
@ -155,13 +175,13 @@ makeTags nsfw sfwTags nsfwTags =
extLinks :: Bool -> [Link] -> Builder
extLinks nsfw allLinks =
if null links then "" else [b|@2
<div class=links>
if null links then "" else [b|@4
<section class=links>
<h2>links</h2>
<ul>
$6.linkList
$8.linkList
</ul>
</div>
</section>
|]
where
links = if nsfw then allLinks else filter #sfw allLinks