gallery/make-pages/IndexPage.hs

67 lines
1.5 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>
<link rel='alternate stylesheet' href=/style/tum/index.css title=tummy>
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>
2020-07-19 06:10:27 -04:00
<h1>$*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-07-20 16:40:34 -04:00
<ul id=gallery-list class=list>
2020-07-19 06:22:02 -04:00
$4.items
</ul>
|]
where items = map makeItem galleries
linkList = if null links then "" else [b|@2
2020-07-20 16:40:34 -04:00
<ul id=link-list class=list>
2020-07-19 06:22:02 -04:00
$4.items
</ul>
|]
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-07-19 12:00:39 -04:00
makeItem (GalleryInfo {title, description, prefix, filters}) = [b|@4
2020-07-20 16:40:34 -04:00
<li$nsfw><a href=$@prefix title="$*description">$*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
makeLink (Link {title, url, nsfw}) = [b|@4
<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
hasNsfw (GalleryFilters {nsfw}) = nsfw /= Just False