diff --git a/package.yaml b/package.yaml index 22bd786..69a02da 100644 --- a/package.yaml +++ b/package.yaml @@ -47,6 +47,7 @@ dependencies: - case-insensitive - wai +- blaze-markup >=0.8 && <0.9 - conduit-combinators >= 1.1 && < 1.2 - friendly-time >=0.4 && < 0.5 - libravatar >=0.4 && <0.5 diff --git a/src/Foundation.hs b/src/Foundation.hs index 2e7e680..ef81603 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -24,6 +24,7 @@ import Package import Entry.Kind ( EntryKind, pluralise ) import Data.Aeson ( encode, object ) +import qualified Text.Blaze.Internal as B import qualified Data.Text.Lazy.Encoding as E -- | The foundation datatype for your application. This can be a good place to @@ -113,6 +114,7 @@ instance Yesod App where -- you to use normal widget features in default-layout. pc <- widgetToPageContent $(widgetFile "default-layout") + let hasPageTitle = not . B.null . pageTitle $ pc withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet") -- The page to be redirected to when authentication is required. diff --git a/src/Handler/Entries.hs b/src/Handler/Entries.hs index aa100a4..42212e3 100644 --- a/src/Handler/Entries.hs +++ b/src/Handler/Entries.hs @@ -1,4 +1,5 @@ {-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} module Handler.Entries where @@ -6,6 +7,7 @@ import Import import Web.Slug ( Slug ) import Yesod.AtomFeed ( atomLink ) +import qualified Data.Text as T import qualified Entry.Kind as K import Widget.Entry ( entryR, hEntry ) @@ -14,9 +16,10 @@ import Widget.Feed ( hFeed ) getEntriesR :: K.EntryKind -> Handler Html getEntriesR kind = do entries <- runDB $ selectList [EntryKind ==. kind] [Desc EntryPublished] + title <- asks $ siteTitle . appSettings defaultLayout $ do setTitle . toHtml . K.pluralise $ kind - FeedKindR kind `atomLink` K.pluralise kind + atomLink (FeedKindR kind) $ T.concat [K.pluralise kind, " ~ ", title] $(widgetFile "entries") checkMatching :: K.EntryKind -> Slug -> Entry -> Bool diff --git a/src/Handler/Feed.hs b/src/Handler/Feed.hs index 57122bd..30eedaf 100644 --- a/src/Handler/Feed.hs +++ b/src/Handler/Feed.hs @@ -32,7 +32,7 @@ toFeed entries@(latestEntry:_) = (toFeed []) , feedUpdated = entryUpdated $ entityVal latestEntry } toFeed [] = Feed - { feedTitle = fromMaybe "" . appTitle $ compileTimeAppSettings + { feedTitle = siteTitle compileTimeAppSettings , feedLinkSelf = FeedR , feedLinkHome = HomeR , feedAuthor = "" diff --git a/src/Handler/Home.hs b/src/Handler/Home.hs index d6e75a0..dd81310 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -15,14 +15,10 @@ import Widget.Feed ( hFeed ) getHomeR :: Handler Html getHomeR = do userE@(Entity userId user) <- runDB . getBy404 $ UniqueUser "dani" - maybeTitle <- asks $ appTitle . appSettings + title <- asks $ siteTitle . appSettings entries <- runDB $ selectList [EntryAuthorId ==. userId] [Desc EntryPublished] defaultLayout $ do - case maybeTitle of - Just title -> do - setTitle $ toHtml title - atomLink FeedR title - Nothing -> return () + atomLink FeedR title toWidgetHead [hamlet| diff --git a/src/Settings.hs b/src/Settings.hs index e1ea0d1..3f73892 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -62,7 +62,7 @@ data AppSettings = AppSettings -- Example app-specific configuration values. , appAnalytics :: Maybe Text -- ^ Google Analytics code - , appTitle :: Maybe Text + , siteTitle :: Text -- ^ Site-wide title. , appAuthDummyLogin :: Bool @@ -93,7 +93,7 @@ instance FromJSON AppSettings where appSkipCombining <- o .:? "skip-combining" .!= defaultDev appAnalytics <- o .:? "analytics" - appTitle <- o .:? "title" + siteTitle <- o .: "title" -- This code enables MySQL's strict mode, without which MySQL will truncate data. -- See https://github.com/yesodweb/persistent/wiki/Database-Configuration#strict-mode for details diff --git a/templates/default-layout-wrapper.hamlet b/templates/default-layout-wrapper.hamlet index e7cb77c..86682ba 100644 --- a/templates/default-layout-wrapper.hamlet +++ b/templates/default-layout-wrapper.hamlet @@ -5,7 +5,10 @@ $doctype 5 -