diff options
| author | Hannes Schulze <contact@haschu.me> | 2026-10-03 23:23:51 +0200 |
|---|---|---|
| committer | Hannes Schulze <contact@haschu.me> | 2026-10-03 23:23:51 +0200 |
| commit | 41dc555f3a4d53a8773a03ac24bed9aea8143bfa (patch) | |
| tree | 743a584897754dd55a3908e572f5f841282e3afa /src | |
| parent | b945c36d932efdaac36db284e82637bdf0193263 (diff) | |
restructure common page layout
Diffstat (limited to 'src')
| -rw-r--r-- | src/Settlr/UI/Page.hs | 29 | ||||
| -rw-r--r-- | src/Settlr/Views/ErrorNotFound.hs | 13 | ||||
| -rw-r--r-- | src/Settlr/Views/Home.hs | 12 |
3 files changed, 38 insertions, 16 deletions
diff --git a/src/Settlr/UI/Page.hs b/src/Settlr/UI/Page.hs new file mode 100644 index 0000000..a3cd497 --- /dev/null +++ b/src/Settlr/UI/Page.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE FlexibleContexts #-} + +module Settlr.UI.Page + ( page + ) where + +import Text.Blaze.Html5 (Html, (!), text, textValue) +import qualified Text.Blaze.Html5 as H +import qualified Text.Blaze.Html5.Attributes as A +import Data.Text (Text) +import Settlr.Config (Config(..)) +import Control.Monad.Reader (MonadReader, asks) + +page + :: MonadReader Config m + => Text -- ^ the page title + -> Html -- ^ main content + -> m Html -- ^ given the config, the rendered page (i.e., the entire html document) +page title content = do + cssPath <- asks cfgCssPath + pure $ H.docTypeHtml $ do + H.head $ do + H.meta ! A.charset "utf-8" + H.title (text (title <> " | Settlr")) + H.link ! A.rel "stylesheet" ! A.href (textValue cssPath) + H.body $ do + H.main $ do + content diff --git a/src/Settlr/Views/ErrorNotFound.hs b/src/Settlr/Views/ErrorNotFound.hs index d087c5e..b8c0712 100644 --- a/src/Settlr/Views/ErrorNotFound.hs +++ b/src/Settlr/Views/ErrorNotFound.hs @@ -5,6 +5,7 @@ module Settlr.Views.ErrorNotFound ) where import Settlr.Config (ScriptM) +import Settlr.UI.Page (page) import Text.Blaze.Html5 (Html, (!), textValue) import qualified Text.Blaze.Html5 as H import qualified Text.Blaze.Html5.Attributes as A @@ -14,11 +15,7 @@ import Network.CGI (setStatus) viewErrorNotFound :: ScriptM Html viewErrorNotFound = do setStatus 404 "Not Found" homePath <- formatRoute RouteHome - pure $ H.docTypeHtml $ do - H.head $ do - H.title "Not Found" - H.meta ! A.charset "utf-8" - H.body $ do - H.h1 "Page Not Found" - H.p "The requested page could not be found" - H.a "Go back home" ! A.href (textValue homePath) + page "Not Found" $ do + H.h1 "Page Not Found" + H.p "The requested page could not be found" + H.a "Go back home" ! A.href (textValue homePath) diff --git a/src/Settlr/Views/Home.hs b/src/Settlr/Views/Home.hs index 14fedfd..eb4aea5 100644 --- a/src/Settlr/Views/Home.hs +++ b/src/Settlr/Views/Home.hs @@ -5,14 +5,10 @@ module Settlr.Views.Home ) where import Settlr.Config (ScriptM) -import Text.Blaze.Html5 (Html, (!)) +import Settlr.UI.Page (page) +import Text.Blaze.Html5 (Html) import qualified Text.Blaze.Html5 as H -import qualified Text.Blaze.Html5.Attributes as A viewHome :: ScriptM Html -viewHome = pure $ H.docTypeHtml $ do - H.head $ do - H.title "Test" - H.meta ! A.charset "utf-8" - H.body $ do - H.p "Hello, world!" +viewHome = page "Home" $ do + H.p "Hello, world!" |
