Make entry names optional, since notes shouldn't have names and articles should

This commit is contained in:
Danielle McLean 2017-10-11 23:34:36 +11:00
parent 10b1ed834a
commit fa992bc861
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
6 changed files with 24 additions and 5 deletions

View file

@ -28,7 +28,7 @@ Profile
Entry Entry
slug Slug Maybe maxlen=255 slug Slug Maybe maxlen=255
kind EntryKind maxlen=255 kind EntryKind maxlen=255
name Text maxlen=255 name Text Maybe maxlen=255
content Text sqltype=longtext content Text sqltype=longtext
published UTCTime published UTCTime
updated UTCTime updated UTCTime

View file

@ -22,6 +22,7 @@ import qualified Yesod.Core.Unsafe as Unsafe
import Package import Package
import Model.Cache ( getCached ) import Model.Cache ( getCached )
import Model.Entry ( entryTitle )
import Model.Entry.Kind ( EntryKind, allEntryKinds, pluralise ) import Model.Entry.Kind ( EntryKind, allEntryKinds, pluralise )
import Data.Aeson ( encode, object ) import Data.Aeson ( encode, object )
@ -179,7 +180,7 @@ instance YesodBreadcrumbs App where
breadcrumb (EntriesR kind) = return (pluralise kind, Just HomeR) breadcrumb (EntriesR kind) = return (pluralise kind, Just HomeR)
breadcrumb (EntryR kind entryId) = do breadcrumb (EntryR kind entryId) = do
(Entity _ entry) <- getCached entryId (Entity _ entry) <- getCached entryId
return (entryName entry, Just $ EntriesR kind) return (entryTitle entry, Just $ EntriesR kind)
breadcrumb (EntryWithSlugR kind entryId _) = breadcrumb $ EntryR kind entryId breadcrumb (EntryWithSlugR kind entryId _) = breadcrumb $ EntryR kind entryId
breadcrumb _ = return ("home", Nothing) breadcrumb _ = return ("home", Nothing)

View file

@ -8,6 +8,7 @@ import Import
import Yesod.AtomFeed ( atomLink ) import Yesod.AtomFeed ( atomLink )
import Model.Cache ( getCached ) import Model.Cache ( getCached )
import Model.Entry ( entryTitle )
import Widget.Entry ( entryR, hEntry ) import Widget.Entry ( entryR, hEntry )
import Widget.Feed ( hFeed ) import Widget.Feed ( hFeed )
@ -36,5 +37,5 @@ renderEntry entry = do
when (actualRoute /= Just correctRoute) $ when (actualRoute /= Just correctRoute) $
redirectWith movedPermanently301 correctRoute redirectWith movedPermanently301 correctRoute
defaultLayout $ do defaultLayout $ do
setTitle . toHtml . entryName . entityVal $ entry setTitle . toHtml . entryTitle . entityVal $ entry
$(widgetFile "entry") $(widgetFile "entry")

View file

@ -5,6 +5,7 @@ module Handler.Feed where
import Import import Import
import Data.Time.Clock.POSIX ( posixSecondsToUTCTime ) import Data.Time.Clock.POSIX ( posixSecondsToUTCTime )
import Model.Entry ( entryTitle )
import Widget.Entry ( entryR ) import Widget.Entry ( entryR )
import qualified Data.Text as T import qualified Data.Text as T
@ -47,7 +48,7 @@ toFeedEntry :: Entity Entry -> FeedEntry (Route App)
toFeedEntry entry = FeedEntry toFeedEntry entry = FeedEntry
{ feedEntryLink = entryR entry { feedEntryLink = entryR entry
, feedEntryUpdated = entryUpdated $ entityVal entry , feedEntryUpdated = entryUpdated $ entityVal entry
, feedEntryTitle = entryName $ entityVal entry , feedEntryTitle = entryTitle $ entityVal entry
, feedEntryContent = toHtml . entryContent . entityVal $ entry , feedEntryContent = toHtml . entryContent . entityVal $ entry
, feedEntryEnclosure = Nothing , feedEntryEnclosure = Nothing
} }

15
src/Model/Entry.hs Normal file
View file

@ -0,0 +1,15 @@
{-# LANGUAGE OverloadedStrings #-}
module Model.Entry where
import Model ( Entry, entryName, entryContent )
import Data.Maybe ( fromMaybe )
import qualified Data.Text as T
entryTitle :: Entry -> T.Text
entryTitle = fromMaybe <$> shorten 30 . entryContent <*> entryName
shorten :: Int -> T.Text -> T.Text
shorten n t
| T.length t > n = flip T.append "..." . T.take (n - 1) $ t
| otherwise = t

View file

@ -1,6 +1,7 @@
<article .h-entry .card.bg-dark> <article .h-entry .card.bg-dark>
<div .card-body> <div .card-body>
<h4 .p-name .card-title>#{entryName entry} $maybe name <- entryName entry
<h4 .p-name .card-title>#{name}
<div .e-content> <div .e-content>
#{entryContent entry} #{entryContent entry}
<div .card-footer> <div .card-footer>