Make both navigation sections optional and disable them when empty

This commit is contained in:
Tissevert 2020-09-29 22:11:53 +02:00
parent 5211379f00
commit e0161173ef
2 changed files with 17 additions and 11 deletions

View file

@ -54,7 +54,7 @@ data Blog = Blog {
, pages :: Collection Page , pages :: Collection Page
, path :: Path , path :: Path
, skin :: Skin , skin :: Skin
, tags :: Map String (Set String) , tags :: Collection (Set String)
, templates :: Templates , templates :: Templates
, urls :: URL , urls :: URL
, wording :: Wording , wording :: Wording

View file

@ -12,8 +12,8 @@ import ArticlesList (
) )
import Blog (Blog(..), Skin(..), URL(..), template) import Blog (Blog(..), Skin(..), URL(..), template)
import Control.Monad.Reader (ReaderT, asks) import Control.Monad.Reader (ReaderT, asks)
import qualified Data.Map as Map (elems, keys) import Data.Map as Map (Map, toList)
import Data.Text (pack, empty) import Data.Text (Text, pack, empty)
import DOM.Card (HasCard) import DOM.Card (HasCard)
import qualified DOM.Card as Card (make) import qualified DOM.Card as Card (make)
import Files (absoluteLink) import Files (absoluteLink)
@ -92,6 +92,16 @@ faviconLink url = link_ [
optional :: (a -> HtmlGenerator ()) -> Maybe a -> HtmlGenerator () optional :: (a -> HtmlGenerator ()) -> Maybe a -> HtmlGenerator ()
optional = maybe (return ()) optional = maybe (return ())
navigationSection ::
Text -> String -> ((String, a) -> HtmlGenerator ()) -> Map String a -> HtmlGenerator ()
navigationSection sectionId templateKey generator collection
| null collection = return ()
| otherwise =
div_ [id_ sectionId, class_ "navigator"] (do
h2_ . toHtml =<< template templateKey []
ul_ . mapM_ generator $ Map.toList collection
)
htmlDocument :: HasContent a => a -> HtmlGenerator () htmlDocument :: HasContent a => a -> HtmlGenerator ()
htmlDocument someContent = htmlDocument someContent =
doctypehtml_ (do doctypehtml_ (do
@ -106,14 +116,10 @@ htmlDocument someContent =
) )
body_ (do body_ (do
maybe defaultBanner toHtmlRaw =<< (asks $skin.$banner) maybe defaultBanner toHtmlRaw =<< (asks $skin.$banner)
div_ [id_ "tags"] (do asks tags >>= navigationSection "tags" "tagsList"
h2_ . toHtml =<< template "tagsList" [] (\(key, _) -> tag key)
ul_ . mapM_ tag . Map.keys =<< asks tags asks pages >>= navigationSection "pages" "pagesList"
) (\(_, page) -> mDLink False $ getMarkdown page)
div_ [id_ "pages"] (do
h2_ . toHtml =<< template "pagesList" []
ul_ . mapM_ (mDLink False . getMarkdown) . Map.elems =<< asks pages
)
div_ [id_ "contents"] $ content someContent div_ [id_ "contents"] $ content someContent
) )
) )