Created
April 1, 2016 03:24
-
-
Save justindthomas/cde3f0cf8036050f04e69a8197658867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Article = Article | |
{ articleId :: Int | |
, title :: T.Text | |
, content :: T.Text | |
, created_at :: LocalTime | |
} | |
splice :: (HasPostgres n, Monad n) => C.Splice n | |
splice = do | |
C.manyWithSplices C.runChildren articleSplices $ | |
lift $ query_ "SELECT * FROM article" | |
where | |
articleSplices = do | |
mapV (C.pureSplice . C.textSplice) $ do | |
"articleId" ## T.pack . show . articleId | |
"articleTitle" ## title | |
"articleContent" ## markdownToHtml . content | |
"articleCreation" ## presentTime created_at | |
markdownToHtml :: T.Text -> T.Text | |
markdownToHtml = T.pack . L.unpack . X.renderHtml . MD.markdown MD.def . L.fromStrict | |
presentTime :: LocalTime -> T.Text | |
presentTime l = do | |
tz <- getCurrentTimeZone | |
T.pack . show . utctDay $ localTimeToUTC tz l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment