module Web.Generate.Contents (Entry (..), toc) where
import Control.Monad (unless)
import Text.Blaze.Html5
import Text.Blaze.Html5.Attributes
data Entry
= Entry
Html
AttributeValue
[Entry]
toc :: [Entry] -> Html
toc :: [Entry] -> Html
toc [Entry]
xs = Html -> Html
nav (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"toc" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
Html -> Html
h2 Html
"Contents"
[Entry] -> Html
toList [Entry]
xs
toList :: [Entry] -> Html
toList :: [Entry] -> Html
toList [Entry]
xs = Html -> Html
ul (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ (Entry -> Html) -> [Entry] -> Html
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Entry -> Html
fromEntry [Entry]
xs
fromEntry :: Entry -> Html
fromEntry :: Entry -> Html
fromEntry (Entry Html
title' AttributeValue
anchor [Entry]
subentries) = do
Html -> Html
li (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
Html -> Html
a (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
href AttributeValue
anchor (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Html
title'
Bool -> Html -> Html
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([Entry] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Entry]
subentries) (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ [Entry] -> Html
toList [Entry]
subentries