module Site.Tag where import Data.List qualified as List import Data.Map.Strict qualified as Map import PyF import Relude import Text.Blaze.Html5 ((!)) import Text.Blaze.Html5 qualified as H --import Text.Blaze.Html5.Attributes qualified as A import Prelude () import Site.Model import Utils.Html renderTags :: Model -> Maybe H.Html renderTags model = do let tags = allTags model if null tags then Nothing else Just do H.aside ! classes ["mb-3"] $ H.nav ! classes [ "tags" , "bg-gray-100" , "border-1" , "border-black" , "p-0" ] $ do H.h2 ! classes [ "bg-black" , "font-bold" , "px-4" , "text-left" , "text-xs" , "text-white" ] $ "All Tags" H.span ! classes ["flex", "flex-wrap", "justify-start", "p-2"] $ forM_ tags $ renderTag model True renderTag :: Model -> Bool -> Tag -> H.Html renderTag model showCount tag = H.a ! smallCaps [ "tag" , "bg-yellow-200" , "float-left" , "hover:bg-yellow-400" , "inline-block" , "m-px" , "pr-1" , "text-black" , "text-xs" , "whitespace-nowrap" ] ! hrefRoute model (RouteFilter (Filter Nothing (Just tag))) $ do openIconic "tag" ! classes ["inline-block", "m-1"] H.span ! classes ["inline-block"] $ H.text $ unTag tag memptyIfFalse showCount $ H.span ! classes ["ml-1", "text-gray-500"] $ [fmt|({count})|] where count = List.length $ List.filter (tag `elem`) $ metaTags . pageMeta <$> Map.elems (modelPosts model)