about summary refs log blame commit diff
path: root/src/RSS.hs
blob: 34804cbf0a5562f5ad60f8ddf8e43ad353e30db5 (plain) (tree)
1
2
3
4
5
6
7
8
9

                             
                               
 




                                              
 

                             



                                                     
                                                     



                                                 
                                                                            

                           
                                               














                                                                                   
                                                            
module RSS (renderFeed) where

import qualified Data.Text as T

import Control.Monad (liftM)
import Data.Maybe    (fromMaybe)
import Data.Time     (UTCTime, getCurrentTime)
import Network.URI
import Text.RSS

import BlogDB  hiding (Title)
import Locales

createChannel :: BlogLang -> UTCTime -> [ChannelElem]
createChannel l  now = [ Language $ show l
                       , Copyright "Vincent Ambo"
                       , WebMaster "tazjin@gmail.com"
                       , ChannelPubDate now
                       ]

createRSS :: BlogLang -> UTCTime -> [Item] -> RSS
createRSS l t = RSS (rssTitle l) (rssLink l) (rssDesc l) (createChannel l t)

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 = liftM (showXML . rssToXML) (createFeed l e)