2017-10-08 01:51:48 -04:00
|
|
|
{-# LANGUAGE NoImplicitPrelude #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
2017-10-08 18:02:42 -04:00
|
|
|
module Widget.Entry ( entryR, hEntry ) where
|
2017-10-08 01:51:48 -04:00
|
|
|
|
|
|
|
import Import
|
|
|
|
|
2017-10-08 18:55:34 -04:00
|
|
|
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
|
|
|
|
|
2017-10-08 18:02:42 -04:00
|
|
|
entryR :: Entity Entry -> Route App
|
|
|
|
entryR (Entity entryId entry) = EntryR (entryKind entry) entryId (entrySlug entry)
|
|
|
|
|
2017-10-08 01:51:48 -04:00
|
|
|
hEntry :: Entity Entry -> Widget
|
|
|
|
hEntry (Entity entryId entry) = do
|
2017-10-08 18:55:34 -04:00
|
|
|
published <- toFormattedTime . entryPublished $ entry
|
|
|
|
updated <- toFormattedTime . entryUpdated $ entry
|
2017-10-08 01:51:48 -04:00
|
|
|
maybeAuthor <- handlerToWidget . runDB . get . entryAuthorId $ entry
|
|
|
|
$(widgetFile "mf2/h-entry")
|