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 +