Simplify site title handling, automatically suffix site title to all pages
This commit is contained in:
parent
4088735c69
commit
1b8a07a5f6
8 changed files with 17 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = ""
|
||||
|
|
|
@ -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 ()
|
||||
toWidgetHead
|
||||
[hamlet|
|
||||
<meta name="author" content=#{userFullName user}>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -5,7 +5,10 @@ $doctype 5
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="generator" content="#{packageName package} #{packageVersion package}">
|
||||
|
||||
<title>#{pageTitle pc}
|
||||
<title>
|
||||
$if hasPageTitle
|
||||
#{pageTitle pc} ~ #
|
||||
#{siteTitle $ appSettings master}
|
||||
$maybe route <- mcurrentRoute
|
||||
<link rel="canonical" href=@{route}>
|
||||
<link rel="sitemap" href=@{SitemapR}>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<header>
|
||||
<nav .navbar .navbar-expand-lg .navbar-dark.bg-dark>
|
||||
$maybe title <- appTitle $ appSettings master
|
||||
<a .navbar-brand rel="home" href=@{HomeR}>#{title}
|
||||
<a .navbar-brand rel="home" href=@{HomeR}>#{siteTitle $ appSettings master}
|
||||
<button type="button" .navbar-toggler data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar" aria-label="Toggle navigation">
|
||||
<span .navbar-toggler-icon>
|
||||
|
||||
|
|
Loading…
Reference in a new issue