gallery/make-pages/IndexPage.hs

84 lines
2.1 KiB
Haskell

module IndexPage (make) where
import qualified Data.Text.Lazy as Lazy
import BuilderQQ
import Info
make :: Text -> IndexInfo -> Lazy.Text
make root info = toLazyText $ make' root info
make' :: Text -> IndexInfo -> Builder
make' root (IndexInfo {title, desc, galleries, links, footer}) = [b|@0
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<link rel=stylesheet href=/style/shiny/index.css>
<link rel=icon href=/style/niss.svg>
<meta name=viewport content="width=1200,viewport-fit=cover">
<meta property=og:type content=og:website>
<meta property=og:title content="$title">
<meta property=og:site_name content="$title">
<meta property=og:description content="$desc">
<meta property=og:image content="$root/style/card.png">
<meta property=og:url content="$url">
<meta name=twitter:site content=@2_gecs>
<meta name=twitter:card content=summary>
<title>$title</title>
<div class=page>
<header>
<h1 id=title>$title</h1>
</header>
<main>
$4.galleryList
$4.linkList
</main>
$2.footer'
</div>
|]
where
galleryList = if null galleries then "" else [b|@0
<nav aria-label="gallery list">
<ul id=gallery-list class=list>
$4.items
</ul>
</nav>
|]
where items = map makeItem galleries
linkList = if null links then "" else [b|@0
<nav aria-label="other links">
<ul id=link-list class=list>
$4.items
</ul>
</nav>
|]
where items = map makeLink links
footer' = case footer of
Nothing -> ""
Just f -> [b|@0
<footer>
$2.f
</footer>
|]
url = [b|$root|]
makeItem :: GalleryInfo -> Builder
makeItem (GalleryInfo {title, desc, prefix, filters}) = [b|@0
<li$nsfw><a href=$prefix title="$desc">$title</a></li>
|]
where nsfw = if hasNsfw filters then [b| class=nsfw|] else ""
makeLink :: Link -> Builder
makeLink (Link {title, url, nsfw}) = [b|@0
<li$nsfw'><a href=$url>$title</a>
|]
where nsfw' = if nsfw then [b| class=nsfw|] else ""
hasNsfw :: GalleryFilters -> Bool
hasNsfw (GalleryFilters {nsfw}) = nsfw /= NoNsfw