From af913e00e347a79928b58fe289ecc72e0830cdba Mon Sep 17 00:00:00 2001 From: Eduardo Trujillo <ed@chromabits.com> Date: Tue, 12 Sep 2017 20:49:54 -0700 Subject: [PATCH] feat(app): Render RSS feed --- app/site.hs | 24 ++++++++++++++++++++++-- templates/post-body.html | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 templates/post-body.html diff --git a/app/site.hs b/app/site.hs index 8a7ed28..6317420 100644 --- a/app/site.hs +++ b/app/site.hs @@ -28,11 +28,11 @@ data SiteConfiguration = SiteConfiguration , siteGaId :: String } +-- CONFIGURATION -------------------------------------------------------------- + serveConf :: HakyllServeConfiguration serveConf = def & hscHakyllConfiguration .~ hakyllConf --- CONFIGURATION -------------------------------------------------------------- - hakyllConf :: Configuration hakyllConf = defaultConfiguration { deployCommand @@ -48,6 +48,15 @@ siteConf = SiteConfiguration , siteGaId = "UA-47694260-1" } +feedConf :: FeedConfiguration +feedConf = FeedConfiguration + { feedTitle = "Chromabits" + , feedDescription = "A personal blog" + , feedAuthorName = "Eduardo Trujillo" + , feedAuthorEmail = "ed+contact@chromabits.com" + , feedRoot = "https://chromabits.com" + } + colors :: [String] colors = ["purple", "yellow", "orange", "red", "cyan", "green", "blue"] @@ -125,6 +134,8 @@ main = hakyllServeWith serveConf $ do <> postCtx pandocHtml5Compiler + >>= loadAndApplyTemplate "templates/post-body.html" ctx + >>= saveSnapshot "content-body" >>= loadAndApplyTemplate "templates/post.html" ctx >>= saveSnapshot "content" >>= loadAndApplyTemplate "templates/full-post.html" ctx @@ -236,6 +247,15 @@ main = hakyllServeWith serveConf $ do match "templates/*" $ compile templateCompiler + create ["feed.rss"] $ do + route idRoute + compile $ do + let context = postCtx <> bodyField "description" + + posts <- fmap (take 10) . recentFirst + =<< loadAllSnapshots ("posts/*" .&&. hasNoVersion) "content-body" + renderRss feedConf context posts + -- CONTEXTS ------------------------------------------------------------------- siteCtx :: Context String diff --git a/templates/post-body.html b/templates/post-body.html new file mode 100644 index 0000000..36d66c2 --- /dev/null +++ b/templates/post-body.html @@ -0,0 +1 @@ +$body$ -- GitLab