-
Notifications
You must be signed in to change notification settings - Fork 2
/
Feed.hs
60 lines (50 loc) · 1.67 KB
/
Feed.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module Handler.Feed
( getFeedR
, getFeedTagR
) where
import Import
import Yesod -- TODO
import Prelude (head)
import Helpers.Post
import Yesod.RssFeed
getFeedR :: Handler RepRss
getFeedR = do
posts' <- runDB $ selectList [PostDraft !=. True] [Desc PostDate, LimitTo 10]
case posts' of
[] -> notFound
posts -> feedFromPosts $ map entityVal posts
-- | Limited to a tag
getFeedTagR :: Text -> Handler RepRss
getFeedTagR tag = do
posts' <- runDB $ do
tags <- selectList [TagName ==. tag] []
let pids = map (tagPost . entityVal) tags
posts <- selectList [PostDraft !=. True, PostId <-. pids] [Desc PostDate]
return $ map entityVal posts
case posts' of
[] -> notFound
posts -> feedFromPosts posts
feedFromPosts :: [Post] -> Handler RepRss
feedFromPosts posts = do
entries <- mapM postToRssEntry posts
rssFeed Feed
{ feedAuthor = "Patrick Brisbin"
, feedTitle = "pbrisbin dot com"
, feedDescription = "New posts on pbrisbin dot com"
, feedLanguage = "en-us"
, feedLinkSelf = FeedR
, feedLinkHome = RootR
, feedUpdated = postDate $ head posts
, feedEntries = entries
}
-- | Note: does not gracefully handle a post with no pandoc or in-db
-- content
postToRssEntry :: Post -> Handler (FeedEntry (Route App))
postToRssEntry post = do
markdown <- liftIO $ postMarkdown post
return FeedEntry
{ feedEntryLink = PostR $ postSlug post
, feedEntryUpdated = postDate post
, feedEntryTitle = postTitle post
, feedEntryContent = markdownToHtml markdown
}