Add an atom feed to blog

This commit is contained in:
Dhananjay Balan 2019-01-12 19:43:27 -05:00
parent 0fcacf308e
commit 55b06f61ca

47
site.hs
View File

@ -3,6 +3,7 @@
import Data.Monoid (mappend)
import Hakyll
import Hakyll.Core.Identifier (toFilePath)
import Hakyll.Web.Feed
import System.FilePath
import Text.Regex (splitRegex, mkRegex)
@ -22,6 +23,15 @@ config = defaultConfiguration {
, deployCommand = "rsync -vrP public/ www:/usr/local/www/nginx/blog/"
}
feedConfig :: FeedConfiguration
feedConfig = FeedConfiguration {
feedTitle = "Binary Strolls"
, feedDescription = "Blag"
, feedAuthorName = "Dhananjay Balan"
, feedRoot = "https://blog.dbalan.in"
, feedAuthorEmail = "blog@dbalan.in"
}
main :: IO ()
main = hakyllWith config $ do
tags <- extractTags
@ -50,24 +60,10 @@ main = hakyllWith config $ do
route $ octopressRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
create ["archive.html"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "blog/*"
let archiveCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Archives" `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls
match "index.html" $ do
route idRoute
compile $ do
@ -83,6 +79,27 @@ main = hakyllWith config $ do
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
create ["archive.html"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "blog/*"
let archiveCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Archives" `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls
create ["atom.xml"] $ do
route idRoute
compile $ do
posts <- fmap (take 5) . recentFirst =<< loadAllSnapshots "blog/*" "content"
let feedCtx = postCtx `mappend`
constField "description" "This is the post description"
renderAtom feedConfig feedCtx posts
match "templates/*" $ compile templateBodyCompiler
--------------------------------------------------------------------------------