module Site.Render where import Data.Map.Strict qualified as Map import Data.Some (Some (..)) import Data.Text qualified as Text import Ema qualified import Ema.CLI qualified import PyF import Relude import Text.Atom.Feed.Export qualified as Export (textFeed) import Text.Blaze.Html.Renderer.Utf8 qualified as H import Text.Blaze.Html5 ((!)) import Text.Blaze.Html5 qualified as H import Text.Blaze.Html5.Attributes qualified as A import Prelude () import Site.Body import Site.Feed import Site.Filter import Site.Model import Site.Page renderRoute :: Some Ema.CLI.Action -> Model -> Route -> Ema.Asset LByteString renderRoute emaAction model route = case route of RoutePage pageName -> Ema.AssetGenerated Ema.Html $ renderHtml $ case Map.lookup pageName (modelPosts model) of Nothing -> error [fmt|Page not found in Model: {pageName:s}|] Just page -> renderPage model (pageName, page) RouteSpecial pageName -> Ema.AssetGenerated Ema.Html $ renderHtml $ case Map.lookup pageName (modelSpecials model) of Nothing -> error [fmt|Special Page not found in Model: {pageName:s}|] Just page -> renderSpecial model page RouteFeeds -> Ema.AssetGenerated Ema.Html $ renderHtml Content { contentTitle = Just "Feeds" , contentHtml = feedList model } RouteFilter filt -> Ema.AssetGenerated Ema.Html $ renderHtml $ renderFilter model filt RouteFilterAtom filt -> Ema.AssetGenerated Ema.Other $ maybe (error "Feed malformed?") encodeUtf8 $ Export.textFeed $ mkFeed model filt where renderHtml content@Content{..} = H.renderHtml do H.docType H.html ! A.lang "fr" $ do H.head do H.meta ! A.charset "UTF-8" -- This makes the site mobile-friendly by default. H.meta ! A.name "viewport" ! A.content "width=device-width, initial-scale=1" -- When Ema.CLI.Generate this is https://unpkg.com/tailwindcss@2/dist/tailwind.css -- When Ema.CLI.Run this is the output of windicss on the generated .html H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href "/static/css/windi.css" when (Ema.CLI.isLiveServer emaAction) $ -- Add WindiCSS classes missing from https://unpkg.com/tailwindcss@2/dist/tailwind.css H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href "/static/css/windi-extras.css" let localTitle = Text.intercalate " - " $ maybeToList contentTitle <> [orgName] H.title $ H.text localTitle --H.base ! A.href "/" let description = "Some description." H.meta ! A.name "description" ! A.content description let openGraph (name :: Text) contentTag = H.meta ! H.customAttribute "property" [fmt|openGraph:{name}|] ! A.content contentTag openGraph "title" $ H.preEscapedTextValue localTitle openGraph "description" description openGraph "image" $ H.preEscapedTextValue $ absoluteLink model $ Left "static/img/image.jpg" openGraph "image:alt" "some logo" openGraph "locale" "fr_FR" openGraph "type" "article" openGraph "url" $ H.preEscapedTextValue $ absoluteLink model $ Left "" -- H.link ! A.rel "icon" ! A.type_ "image/png" ! A.href "/static/img/favicon.png" H.link ! A.href "/static/css/extra.css" ! A.rel "stylesheet" ! A.type_ "text/css" H.link ! hrefRoute model (RouteFilterAtom $ Filter Nothing Nothing) ! A.rel "alternate" ! A.title [fmt|{orgName} - All Posts|] ! A.type_ "application/atom+xml" renderBody model route content