gallery/make-pages/IndexPage.hs

70 lines
1.6 KiB
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 BuilderQQ
import Info
2020-07-18 05:45:32 -04:00
make :: IndexInfo -> Lazy.Text
2020-07-19 06:10:27 -04:00
make info = toLazyText $ make' info
2020-07-16 10:29:32 -04:00
2020-07-18 05:45:32 -04:00
make' :: IndexInfo -> Builder
2020-07-19 06:22:02 -04:00
make' (IndexInfo {title, galleries, links, footer}) = [b|@0
2020-07-16 10:29:32 -04:00
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
2020-07-21 03:16:05 -04:00
<link rel=stylesheet href=/style/shiny/index.css title=shiny>
2020-07-16 10:29:32 -04:00
2020-07-19 06:10:27 -04:00
<title>$*title</title>
2020-07-16 10:29:32 -04:00
<header>
<h1 id=title>$*title</h1>
2020-07-16 10:29:32 -04:00
</header>
<main>
2020-07-19 06:22:02 -04:00
$galleryList
$linkList
2020-07-16 10:29:32 -04:00
</main>
2020-07-18 05:45:32 -04:00
2020-07-19 06:22:02 -04:00
$footer'
2020-07-16 10:29:32 -04:00
|]
where
2020-07-19 06:22:02 -04:00
galleryList = if null galleries then "" else [b|@2
2020-08-04 12:56:44 -04:00
<nav aria-label="gallery list">
<ul id=gallery-list class=list>
$6.items
</ul>
</nav>
2020-07-19 06:22:02 -04:00
|]
where items = map makeItem galleries
linkList = if null links then "" else [b|@2
2020-08-04 12:56:44 -04:00
<nav aria-label="other links">
<ul id=link-list class=list>
$6.items
</ul>
</nav>
2020-07-19 06:22:02 -04:00
|]
where items = map makeLink links
footer' = case footer of
Nothing -> ""
Just f -> [b|@0
<footer>
$2*f
</footer>
|]
2020-07-16 10:29:32 -04:00
makeItem :: GalleryInfo -> Builder
2020-08-04 12:56:44 -04:00
makeItem (GalleryInfo {title, desc, prefix, filters}) = [b|@6
2020-07-24 19:17:47 -04:00
<li$nsfw><a href=$@prefix title="$*desc">$*title</a></li>
2020-07-16 10:29:32 -04:00
|]
2020-07-19 06:22:02 -04:00
where nsfw = if hasNsfw filters then " class=nsfw" else ""
makeLink :: Link -> Builder
2020-08-04 12:56:44 -04:00
makeLink (Link {title, url, nsfw}) = [b|@6
2020-07-19 06:22:02 -04:00
<li$nsfw'><a href=$*url>$*title</a>
|]
where nsfw' = if nsfw then " class=nsfw" else ""
2020-07-17 06:29:13 -04:00
hasNsfw :: GalleryFilters -> Bool
2020-07-24 19:10:52 -04:00
hasNsfw (GalleryFilters {nsfw}) = nsfw /= NoNsfw