module IndexPage (make) where
import qualified Data.Text.Lazy as Lazy
import BuilderQQ
import Info
make :: IndexInfo -> Lazy.Text
make info = toLazyText $ make' info
make' :: IndexInfo -> Builder
make' (IndexInfo {title, galleries, links, footer}) = [b|@0
$*title
$galleryList
$linkList
$footer'
|]
where
galleryList = if null galleries then "" else [b|@2
|]
where items = map makeItem galleries
linkList = if null links then "" else [b|@2
|]
where items = map makeLink links
footer' = case footer of
Nothing -> ""
Just f -> [b|@0
|]
makeItem :: GalleryInfo -> Builder
makeItem (GalleryInfo {title, desc, prefix, filters}) = [b|@4
$*title
|]
where nsfw = if hasNsfw filters then " class=nsfw" else ""
makeLink :: Link -> Builder
makeLink (Link {title, url, nsfw}) = [b|@4
$*title
|]
where nsfw' = if nsfw then " class=nsfw" else ""
hasNsfw :: GalleryFilters -> Bool
hasNsfw (GalleryFilters {nsfw}) = nsfw /= NoNsfw