on master help sign in
Fix feed generator when item contains CDATA
commit43d2736a2b1dd7345bcb6d9016c04e471c002ffd authorYann Esposito (Yogsototh) <yann.esposito@gmail.com> dateThu 18 Aug 2016, 01:22 (10 years ago) parent2ef6d11
1 file changed+7−1
src/Hakyll/Web/Feed.hs+7−1
src/Hakyll/Web/Feed.hs+7−1
@@ -27,6 +27,7 @@ module Hakyll.Web.Feed
2727import Hakyll.Core.Compiler
2828import Hakyll.Core.Compiler.Internal
2929import Hakyll.Core.Item
30+import Hakyll.Core.Util.String (replaceAll)
3031import Hakyll.Web.Template
3132import Hakyll.Web.Template.Context
3233import Hakyll.Web.Template.List
@@ -64,9 +65,14 @@ renderFeed feedPath itemPath config itemContext items = do
6465 feedTpl <- loadTemplate feedPath
6566 itemTpl <- loadTemplate itemPath
6667
67− body <- makeItem =<< applyTemplateList itemTpl itemContext' items
68+ protectedItems <- mapM (applyFilter protectCDATA) items
69+ body <- makeItem =<< applyTemplateList itemTpl itemContext' protectedItems
6870 applyTemplate feedTpl feedContext body
6971 where
72+ applyFilter :: (Monad m,Functor f) => (String -> String) -> f String -> m (f String)
73+ applyFilter tr str = return $ fmap tr str
74+ protectCDATA :: String -> String
75+ protectCDATA = replaceAll "]]>" (const "]]&gt;")
7076 -- Auxiliary: load a template from a datafile
7177 loadTemplate path = do
7278 file <- compilerUnsafeIO $ getDataFileName path