From f3a17454fae3b140ada30ebef13f508179f4cd0d Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Sat, 24 Nov 2018 17:06:54 +0530 Subject: Adds render{Rss,Atom}WithTemmplates function in the Web.Feed module --- lib/Hakyll/Web/Feed.hs | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/Hakyll/Web/Feed.hs b/lib/Hakyll/Web/Feed.hs index 6e12146..531d653 100644 --- a/lib/Hakyll/Web/Feed.hs +++ b/lib/Hakyll/Web/Feed.hs @@ -22,6 +22,8 @@ module Hakyll.Web.Feed ( FeedConfiguration (..) , renderRss , renderAtom + , renderRssWithTemplates + , renderAtomWithTemplates ) where @@ -125,15 +127,41 @@ renderFeed defFeed defItem config itemContext items = do readTemplateFile value = pure $ template $ readTemplateElems value +-------------------------------------------------------------------------------- +-- | Render an RSS feed using given templates with a number of items. +renderRssWithTemplates :: + String -- ^ Feed template + -> String -- ^ Item template + -> FeedConfiguration -- ^ Feed configuration + -> Context String -- ^ Item context + -> [Item String] -- ^ Feed items + -> Compiler (Item String) -- ^ Resulting feed +renderRssWithTemplates feedTemplate itemTemplate config context = renderFeed + feedTemplate itemTemplate config + (makeItemContext "%a, %d %b %Y %H:%M:%S UT" context) + + +-------------------------------------------------------------------------------- +-- | Render an Atom feed using given templates with a number of items. +renderAtomWithTemplates :: + String -- ^ Feed template + -> String -- ^ Item template + -> FeedConfiguration -- ^ Feed configuration + -> Context String -- ^ Item context + -> [Item String] -- ^ Feed items + -> Compiler (Item String) -- ^ Resulting feed +renderAtomWithTemplates feedTemplate itemTemplate config context = renderFeed + feedTemplate itemTemplate config + (makeItemContext "%Y-%m-%dT%H:%M:%SZ" context) + + -------------------------------------------------------------------------------- -- | Render an RSS feed with a number of items. renderRss :: FeedConfiguration -- ^ Feed configuration -> Context String -- ^ Item context -> [Item String] -- ^ Feed items -> Compiler (Item String) -- ^ Resulting feed -renderRss config context = renderFeed - rssTemplate rssItemTemplate config - (makeItemContext "%a, %d %b %Y %H:%M:%S UT" context) +renderRss = renderRssWithTemplates rssTemplate rssItemTemplate -------------------------------------------------------------------------------- @@ -142,9 +170,7 @@ renderAtom :: FeedConfiguration -- ^ Feed configuration -> Context String -- ^ Item context -> [Item String] -- ^ Feed items -> Compiler (Item String) -- ^ Resulting feed -renderAtom config context = renderFeed - atomTemplate atomItemTemplate config - (makeItemContext "%Y-%m-%dT%H:%M:%SZ" context) +renderAtom = renderAtomWithTemplates atomTemplate atomItemTemplate -------------------------------------------------------------------------------- -- cgit v1.2.3