From 934457f671a1c249415297e13ba85fe4439bedab Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Mon, 9 Oct 2017 09:55:34 +1100 Subject: [PATCH] Pretty up the h-entry as a Bootstrap card --- package.yaml | 1 + src/Widget/Entry.hs | 12 ++++++++++++ templates/mf2/h-entry.hamlet | 26 ++++++++++++++------------ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/package.yaml b/package.yaml index 859a5b0..8a4662b 100644 --- a/package.yaml +++ b/package.yaml @@ -48,6 +48,7 @@ dependencies: - wai - conduit-combinators >= 1.1 && < 1.2 +- friendly-time >=0.4 && < 0.5 - libravatar >=0.4 && <0.5 - slug >=0.1 && <0.2 - split >=0.2 && <0.3 diff --git a/src/Widget/Entry.hs b/src/Widget/Entry.hs index dbf1a06..07e02a7 100644 --- a/src/Widget/Entry.hs +++ b/src/Widget/Entry.hs @@ -5,10 +5,22 @@ module Widget.Entry ( entryR, hEntry ) where import Import +import Data.Time.Format ( defaultTimeLocale, formatTime, iso8601DateFormat ) +import Data.Time.Format.Human ( humanReadableTime ) + +data FormattedTime = FormattedTime { timeUnfriendly :: String, timeFriendly :: String } + +toFormattedTime :: MonadIO m => UTCTime -> m FormattedTime +toFormattedTime time = FormattedTime (unfriendly time) <$> friendly time + where unfriendly = formatTime defaultTimeLocale . iso8601DateFormat . Just $ "%H:%M:%S%z" + friendly = liftIO . humanReadableTime + entryR :: Entity Entry -> Route App entryR (Entity entryId entry) = EntryR (entryKind entry) entryId (entrySlug entry) hEntry :: Entity Entry -> Widget hEntry (Entity entryId entry) = do + published <- toFormattedTime . entryPublished $ entry + updated <- toFormattedTime . entryUpdated $ entry maybeAuthor <- handlerToWidget . runDB . get . entryAuthorId $ entry $(widgetFile "mf2/h-entry") diff --git a/templates/mf2/h-entry.hamlet b/templates/mf2/h-entry.hamlet index 20a984a..379fccf 100644 --- a/templates/mf2/h-entry.hamlet +++ b/templates/mf2/h-entry.hamlet @@ -1,13 +1,15 @@ -
-

#{entryName entry} - permalink -

- published +