packages feed

panda-0.0.0.5.1: Panda/Model/Post.hs

-- what about the performance?
-- Haskell takes care of that, since IOs are also lazy.
-- Posts are not read unless specifically required, i.e. after pagination

module Panda.Model.Post where

-- env
import Panda.Helper.Env hiding (match, title, body)
import Prelude hiding ((.), (/), id, readFile)
import qualified Panda.Config.Global as Config
import Panda.Type.Reader

data Post = Post 
  { uid :: String     -- blog/08-09-04 blog title
  , title :: String
  , body :: String
  , tags :: [String]
  , reader :: Reader
  }
  deriving (Show, Eq)

list = ls Config.blog_uri <.> rsort <.> map (Config.blog_id /) >>= mapM get

get id        = liftM3 (Post id (get_title id) ) (get_body id) (return []) (return $ get_reader id)
get_title id  = id.from_utf8.words.tail.unwords.dropExtension
get_body id   = (Config.flat_uri / id) .readFile
get_reader id = id.take_extension.guess_reader.fromMaybe Config.default_reader


parse_date = parseCalendarTime defaultTimeLocale "%Y-%m-%d"
date x     = x.uid.words.first.split "/".last.("20"++).parse_date.fromMaybe (parse_date "2000-1-1".fromJust)


match s x = [title, body] .map (send_to x >>> lower >>> isInfixOf (s.lower)) .or
search "" = return []
search s  = list <.> filter (match s)

markup x = render_to_html (x.reader) (x.body)