gallery/make-pages/IndexPage.hs

42 lines
900 B
Haskell

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>
<link rel=stylesheet href=/style/index.css>
<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
makeItem (GalleryInfo {title, prefix, filters}) = [b|@4
<li$nsfw><a href=$@prefix>$*title</a>
|]
where
nsfw = if hasNsfw filters then " class=nsfw" else ""
hasNsfw :: GalleryFilters -> Bool
hasNsfw (GalleryFilters {nsfw}) = nsfw /= Just False