gallery/make-pages/IndexPage.hs

43 lines
900 B
Haskell
Raw Normal View History

2020-07-16 10:29:32 -04:00
module IndexPage (make) where
import qualified Data.Text.Lazy as Lazy
import Data.Text.Lazy.Builder (Builder, toLazyText)
import BuilderQQ
import Info
make :: [GalleryInfo] -> Lazy.Text
make ginfos = toLazyText $ make' ginfos
make' :: [GalleryInfo] -> Builder
make' ginfos = [b|@0
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
2020-07-17 06:29:13 -04:00
<link rel=stylesheet href=/style/index.css>
2020-07-16 10:29:32 -04:00
<title>gallery list</title>
<header>
<h1>gallery list</h1>
</header>
<main>
<ul class=gallery-list>
$4.items
</ul>
</main>
|]
where
items = map makeItem ginfos
makeItem :: GalleryInfo -> Builder
2020-07-17 06:29:13 -04:00
makeItem (GalleryInfo {title, prefix, filters}) = [b|@4
<li$nsfw><a href=$@prefix>$*title</a>
2020-07-16 10:29:32 -04:00
|]
2020-07-17 06:29:13 -04:00
where
nsfw = if hasNsfw filters then " class=nsfw" else ""
hasNsfw :: GalleryFilters -> Bool
hasNsfw (GalleryFilters {nsfw}) = nsfw /= Just False