module Site.Body where import Data.List qualified as List import Data.Map.Strict qualified as Map import Data.Text qualified as Text import Data.Time qualified as Time import Ema import Ema qualified import Network.URI.Slug (decodeSlug, encodeSlug) import PyF import Relude import Text.Blaze qualified as B 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 renderBody :: Model -> Route -> Content -> H.Html renderBody model@Model{..} route Content{..} = -- The "overflow-y-scroll" makes the scrollbar visible always, so as to -- avoid content shifts when switching to routes with suddenly scrollable content. H.body ! classes [ "bg-gray-50" , "flex" , "flex-col" , "overflow-y-scroll" , "font-sans" , --, "max-w-prose" --, "mx-auto" "text-xs" , "mx-4" , "px-4" , "block" ] $ do --renderNav model route renderBodyHead H.hr contentHtml where -- H.hr -- renderBodyFoot renderBodyHead = H.nav ! classes [ "text-xs" ] $ case route of RoutePage page | Just{} <- Map.lookup page modelPosts -> html ("post" : page) RouteSpecial page | Just{} <- Map.lookup page modelSpecials -> html page RouteFilter filt@Filter{..} | maybe True (`elem` allTagsModel) filterTag -> html $ "list" : encodeFilter filt RouteFeeds -> html ["feeds"] RouteFilterAtom filt@Filter{..} | maybe True (`elem` allTagsModel) filterTag -> html $ "feed" : encodeFilter filt _notFound -> --error [fmt|Route {notFound:s} does not exist.|] html ["not-found"] where allTagsModel = allTags model html slugs = H.ul ! classes [ "items-start" , "flex" , "flex-wrap" , "justify-start" ] $ mconcat $ List.intersperse "/" [ H.li ! classes (if path == [] then ["pr-2"] else ["px-2"]) $ H.a ! A.href (B.toValue $ encodeSlugs path) $ H.text $ encodeSlug slug | (slug, path) <- List.zip (decodeSlug (Text.toLower orgName) : slugs) (List.inits slugs) ] renderBodyFoot = H.footer ! classes [ "border-t-2" , "flex" , "flex-row" , "justify-between" , "mt-4" , "text-sm" , "clear-left" ] $ do {- H.a ! classes ["hover:bg-blue-100", "text-blue-600"] ! A.href [fmt|{Ema.routeUrl model $ Right @FilePath route:s}#top|] $ "Back to top" -} H.span ! classes ["text-gray-600"] $ [fmt|Generated: {maybe "dynamically" (Time.formatTime Time.defaultTimeLocale "%F") modelTime }|] H.span do "The " H.a ! A.href [fmt|https://git.code.{domainName}/~julm/sourcephile-web|] $ "code for this site" " is " H.a ! A.href "https://spdx.org/licenses/AGPL-3.0-or-later.html" $ "AGPL-3.0-or-later" "." {- renderNav :: Model -> Route -> H.Html renderNav model route = H.div ! A.id "top" ! classes ["bg-gray-500"] $ H.nav ! classes [ "flex" , "flex-col" , "items-stretch" , "max-w-6xl" , "mx-auto" , "sm:flex-row" , "sm:h-16" , "sm:justify-between" ] $ do H.span ! classes [ "flex" , "flex-col" , "items-stretch" , "sm:flex-row" , "sm:justify-start" ] $ headLinks [ ( A.href "#" , do --H.img -- ! classes ["w-10", "h-10", "mr-4", "rounded-full"] -- ! A.src "/static/img/my_avatar.jpg" -- ! A.alt "logo" [fmt|{orgName}|] ) , (hrefRoute model $ RouteFilter noFilter, "All Posts") , (hrefRoute model $ RouteFilter noFilter{filterTag = Just $ Tag "non-tech"}, "Non-Tech") , (hrefRoute model $ RouteFilter noFilter{filterTag = Just $ Tag "tech"}, "Tech") , (hrefRoute model $ RouteSpecial ["projects"], "Projects") ] H.span ! classes ["flex", "flex-row", "justify-items-center"] $ headLinks [ (A.title "Atom" <> hrefRoute model RouteFeeds, openIconic "rss") , (A.title "IRC" <> A.href [fmt|irc://irc.geeknode.org/#sourcephile|], openIconic "chat") , (A.title "XMPP" <> A.href [fmt|xmpp:sourcephile@{domainName}?join|], openIconic "chat") , (A.title "Mail" <> A.href [fmt|mailto:contact@{domainName}|], openIconic "envelope-closed") , (A.title "Git" <> A.href [fmt|https://git.code.{domainName}|], openIconic "fork") ] where headLinks = mapM_ $ \(attrs, html) -> H.a ! smallCaps [ "flex" , "flex-row" , "hover:bg-blue-600" , "items-center" , "justify-center" , "justify-items-center" , "p-4" , "sm:w-auto" , "text-lg" , "text-white" , "w-full" ] ! A.style "font-variant: small-caps" ! attrs $ html ! classes ["w-4"] -}