diff options
author | Vincent Ambo <tazjin@googlemail.com> | 2012-03-23T23·32+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@googlemail.com> | 2012-03-23T23·32+0100 |
commit | efbec9ff76ada0e59f8fc5c37a4c2734ccbf7ce2 (patch) | |
tree | 1b61546620799319152f27c08aeefab3321335db /src/RSS.hs | |
parent | a405e185bac6673645d96defb3800b7a18ca351d (diff) |
* added RSS.hs: functions to create an RSS feed
* added RSS feed handler * FromReqURI instance for BlogLang * fixed RSS-feed link
Diffstat (limited to 'src/RSS.hs')
-rw-r--r-- | src/RSS.hs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/RSS.hs b/src/RSS.hs new file mode 100644 index 000000000000..05ae40ece58f --- /dev/null +++ b/src/RSS.hs @@ -0,0 +1,42 @@ +{-# LANGUAGE RecordWildCards #-} + +module RSS (renderFeed) where + +import qualified Data.Text as T + +import Data.Maybe (fromMaybe) +import Data.Time (getCurrentTime, UTCTime) +import Network.URI +import Text.RSS + +import Locales +import BlogDB hiding (Title) + +createChannel :: BlogLang -> UTCTime -> [ChannelElem] +createChannel l now = [ Language $ show l + , Copyright "Vincent Ambo" + , WebMaster "tazjin@googlemail.com" + , ChannelPubDate now + ] + +createRSS :: BlogLang -> UTCTime -> [Item] -> RSS +createRSS l t i = RSS (rssTitle l) (rssLink l) (rssDesc l) (createChannel l t) i + +createItem :: Entry -> Item +createItem Entry{..} = [ Title $ T.unpack title + , Link $ makeLink lang entryId + , Description $ T.unpack btext + , PubDate edate] + +makeLink :: BlogLang -> EntryId -> URI +makeLink l i = let url = "http://tazj.in/" ++ show l ++ "/" ++ show i + in fromMaybe nullURI $ parseURI url + +createItems :: [Entry] -> [Item] +createItems = map createItem + +createFeed :: BlogLang -> [Entry] -> IO RSS +createFeed l e = getCurrentTime >>= (\t -> return $ createRSS l t $ createItems e ) + +renderFeed :: BlogLang -> [Entry] -> IO String +renderFeed l e = createFeed l e >>= (\feed -> return $ showXML $ rssToXML feed) \ No newline at end of file |