-- | A Module that allows easy rendering of RSS feeds.---- The main rendering functions (@renderRss@, @renderAtom@) all assume that-- you pass the list of items so that the most recent entry in the feed is the-- first item in the list.---- Also note that the pages should have (at least) the following fields to-- produce a correct feed:---- - @$title@: Title of the item---- - @$description@: Description to appear in the feed---- - @$url@: URL to the item - this is usually set automatically.---- In addition, the posts should be named according to the rules for-- 'Hakyll.Page.Metadata.renderDateField'.--moduleHakyll.Web.Feed(FeedConfiguration(..),renderRss,renderAtom)whereimportPreludehiding(id)importControl.Category(id)importControl.Arrow((>>>),arr,(&&&))importControl.Monad((<=<))importData.Maybe(fromMaybe,listToMaybe)importHakyll.Core.CompilerimportHakyll.Web.PageimportHakyll.Web.Page.MetadataimportHakyll.Web.TemplateimportHakyll.Web.Template.Read.Hakyll(readTemplate)importHakyll.Web.Util.UrlimportPaths_hakyll-- | This is a data structure to keep the configuration of a feed.dataFeedConfiguration=FeedConfiguration{-- | Title of the feed.feedTitle::String,-- | Description of the feed.feedDescription::String,-- | Name of the feed author.feedAuthorName::String,-- | Absolute root URL of the feed site (e.g. @http://jaspervdj.be@)feedRoot::String}deriving(Show,Eq)-- | This is an auxiliary function to create a listing that is, in fact, a feed.-- The items should be sorted on date. The @$timestamp@ field should be set.--createFeed::Template-- ^ Feed template->Template-- ^ Item template->String-- ^ URL of the feed->FeedConfiguration-- ^ Feed configuration->[PageString]-- ^ Items to include->String-- ^ Resulting feedcreateFeedfeedTemplateitemTemplateurlconfigurationitems=pageBody$applyTemplatefeedTemplate$trySetField"timestamp"timestamp$trySetField"title"(feedTitleconfiguration)$trySetField"description"(feedDescriptionconfiguration)$trySetField"authorName"(feedDescriptionconfiguration)$trySetField"root"(feedRootconfiguration)$trySetField"url"url$fromBodybodywhere-- Preprocess itemsitems'=flipmapitems$applyTemplateitemTemplate.trySetField"root"(feedRootconfiguration)-- Body: concatenated itemsbody=concat$mappageBodyitems'-- Take the first timestamp, which should be the most recenttimestamp=fromMaybe"Unknown"$dop<-listToMaybeitemsreturn$getField"timestamp"p-- | Abstract function to render any feed.--renderFeed::FilePath-- ^ Feed template->FilePath-- ^ Item template->FeedConfiguration-- ^ Feed configuration->Compiler[PageString]String-- ^ Feed compilerrenderFeedfeedTemplateitemTemplateconfiguration=id&&&getRoute>>>renderFeed'where-- Arrow rendering the feed from the items and the URLrenderFeed'=unsafeCompiler$\(items,url)->dofeedTemplate'<-loadTemplatefeedTemplateitemTemplate'<-loadTemplateitemTemplateleturl'=toUrl$fromMaybenoUrlurlreturn$createFeedfeedTemplate'itemTemplate'url'configurationitems-- Auxiliary: load a template from a datafileloadTemplate=fmapreadTemplate.readFile<=<getDataFileName-- URL is required to have a valid fieldnoUrl=error"Hakyll.Web.Feed.renderFeed: no route specified"-- | Render an RSS feed with a number of items.--renderRss::FeedConfiguration-- ^ Feed configuration->Compiler[PageString]String-- ^ Feed compilerrenderRssconfiguration=arr(maprenderDate)>>>renderFeed"templates/rss.xml""templates/rss-item.xml"configurationwhererenderDate=renderDateField"timestamp""%a, %d %b %Y %H:%M:%S UT""No date found."-- | Render an Atom feed with a number of items.--renderAtom::FeedConfiguration-- ^ Feed configuration->Compiler[PageString]String-- ^ Feed compilerrenderAtomconfiguration=arr(maprenderDate)>>>renderFeed"templates/atom.xml""templates/atom-item.xml"configurationwhererenderDate=renderDateField"timestamp""%Y-%m-%dT%H:%M:%SZ""No date found."