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 Data.Monoid (mappend)
import Hakyll import Hakyll
import Hakyll.Core.Identifier (toFilePath) import Hakyll.Core.Identifier (toFilePath)
import Hakyll.Web.Feed
import System.FilePath import System.FilePath
import Text.Regex (splitRegex, mkRegex) import Text.Regex (splitRegex, mkRegex)
@ -22,6 +23,15 @@ config = defaultConfiguration {
, deployCommand = "rsync -vrP public/ www:/usr/local/www/nginx/blog/" , 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 :: IO ()
main = hakyllWith config $ do main = hakyllWith config $ do
tags <- extractTags tags <- extractTags
@ -50,24 +60,10 @@ main = hakyllWith config $ do
route $ octopressRoute route $ octopressRoute
compile $ pandocCompiler compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx >>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx >>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls >>= 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 match "index.html" $ do
route idRoute route idRoute
compile $ do compile $ do
@ -83,6 +79,27 @@ main = hakyllWith config $ do
>>= loadAndApplyTemplate "templates/default.html" indexCtx >>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls >>= 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 match "templates/*" $ compile templateBodyCompiler
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------