packages feed

bamboo-2009.6.6: src/Bamboo/View/Widget/RSS.hs

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NamedFieldPuns #-}

module Bamboo.View.Widget.RSS where

-- env
import Bamboo.View.Env hiding (render_rss, title, link, config)
import Bamboo.Type.State
import Bamboo.Type ( author_email, blog_title, host_name, root, summary_for_rss)
import Text.RSS hiding (RSS)
import qualified Text.RSS as RSS

-- model
import Bamboo.Model.Post hiding (title)
import qualified Bamboo.Model.Post as Post 

-- RSS
instance Default URI where
  def = nullURI

data RSS = RSS
  {
    title :: RSS.Title
  , link :: RSS.Link
  , description :: RSS.Description
  , channel_elems :: [RSS.ChannelElem]
  , items :: [RSS.Item]
  }

to_rss :: RSS -> RSS.RSS
to_rss x = RSS.RSS 
  (x.title) (x.link) (x.description) (x.channel_elems) (x.items)

rss :: State -> String -> String -> String
rss s categary title' = RSS
  {
    title
  , link
  , description = title'
  , channel_elems = [ RSS.Language "en-us" ]
  , items
  }
  .to_rss.rssToXML.showXML
  where
    full_uri x = def { uriScheme = "http://", uriPath = host_link x }
    host_link x = s.config.host_name ++ (s.config.root / x)
    link = full_uri (categary / title)
    title = 
      if title'.empty 
        then s.config.blog_title
        else s.config.blog_title ++ " / " ++ title'
    items = s.posts.map item_rss_template
    
    item_rss_template x = 
      [ Title $ x.Post.title
      , Description $ x.render_rss
      , Author $ s.config.author_email
      , Link $ full_uri (x.uri)
      , PubDate $ x.date
      ]
      
    render_rss x  
      | s.config.summary_for_rss.is True = x.markup_summary.show
      | otherwise                        = x.markup.show