-- |A simple feed generator: Feed data structure -- -- Copyright (c) 2006 Manuel M T Chakravarty -- -- License: -- --- Description --------------------------------------------------------------- -- -- Language: Haskell 98 -- module Feed ( -- * Internal representation of feeds URL, Feed(..), Channel(..), Image(..), Category(..), Item(..), Enclosure(..), GUID(..), Source(..), Info(..), -- * Copying of non-parametric components of channels copyChannelInfo, -- * Default values for all feed sub-structures defaultChannel, defaultImage, defaultCategory, defaultItem, defaultEnclosure, defaultGUID, defaultSource ) where -- lambdaFeed import Date ( Date) -- Feed data structure (following RSS 2.0.1 (rv 6)) -- ------------------- -- URL data type -- type URL = String -- A feed consists of a set of channels. -- data Feed items = Feed [Channel items] deriving Show -- Channel description -- data Channel items = Channel { titleChan :: String, linkChan :: URL, descriptionChan :: String, languageChan :: Maybe String, copyrightChan :: Maybe String, managingEditorChan :: Maybe String, webMasterChan :: Maybe String, pubDateChan :: Maybe Date, lastBuildDateChan :: Maybe Date, categoryChan :: [Category], -- may be empty generatorChan :: Maybe String, docsChan :: Maybe URL, cloudChan :: (), ttlChan :: Maybe Int, -- in minutes imageChan :: Maybe Image, ratingChan :: (), textInputChan :: (), skipHoursChan :: (), skipDaysChan :: (), itemsChan :: items, infoChan :: Info -- internal info about a channel } deriving Show -- Generic categorisation information -- data Category = Category { categoryCategory :: String, domainCategory :: Maybe String } deriving Show -- Inline image -- data Image = Image { urlImage :: URL, titleImage :: String, linkImage :: URL, widthImage :: Maybe Int, heightImage :: Maybe Int, descriptionImage :: Maybe String } deriving Show -- Feed item -- -- * Either `titleItem' or `descriptionItem' must be present. -- data Item = Item { titleItem :: Maybe String, linkItem :: Maybe URL, descriptionItem :: Maybe String, authorItem :: Maybe String, -- email of author categoryItem :: [Category], -- may be empty commentsItem :: Maybe URL, enclosureItem :: Maybe Enclosure, guidItem :: Maybe GUID, pubDateItem :: Maybe Date, sourceItem :: Maybe Source } deriving Show -- Inline media content -- data Enclosure = Enclosure { urlEnclosure :: URL, lengthEnclosure :: Int, -- in bytes typeEnclosure :: String } deriving Show -- Global identification -- data GUID = GUID { guidGUID :: String, isPermaLinkGUID :: Maybe Bool } deriving Show -- Item source -- data Source = Source { sourceSource :: String, urlSource :: URL } deriving Show -- lambdaFeed specific information about a channel -- data Info = Info { fnameInfo :: FilePath -- basename of .lfc } deriving Show -- Copies all components of a channel structure except `itemsChan'. -- copyChannelInfo :: Channel a -> Channel b copyChannelInfo chan = Channel { titleChan = titleChan chan, linkChan = linkChan chan, descriptionChan = descriptionChan chan, languageChan = languageChan chan, copyrightChan = copyrightChan chan, managingEditorChan = managingEditorChan chan, webMasterChan = webMasterChan chan, pubDateChan = pubDateChan chan, lastBuildDateChan = lastBuildDateChan chan, categoryChan = categoryChan chan, generatorChan = generatorChan chan, docsChan = docsChan chan, cloudChan = cloudChan chan, ttlChan = ttlChan chan, imageChan = imageChan chan, ratingChan = ratingChan chan, textInputChan = textInputChan chan, skipHoursChan = skipHoursChan chan, skipDaysChan = skipDaysChan chan, itemsChan = error "channel missing items (after copy)", infoChan = infoChan chan } -- Channel value with default components. -- defaultChannel :: Channel items defaultChannel = Channel { titleChan = error "channel missing title", linkChan = error "channel missing link", descriptionChan = error "channel missing description", languageChan = Nothing, copyrightChan = Nothing, managingEditorChan = Nothing, webMasterChan = Nothing, pubDateChan = Nothing, lastBuildDateChan = Nothing, categoryChan = [], generatorChan = Nothing, docsChan = Nothing, cloudChan = (), ttlChan = Nothing, imageChan = Nothing, ratingChan = (), textInputChan = (), skipHoursChan = (), skipDaysChan = (), itemsChan = error "channel missing items", infoChan = error "channel missing info" } -- Image value with default components. -- defaultImage :: Image defaultImage = Image { urlImage = error "image missing url", titleImage = error "image missing title", linkImage = error "image missing link", widthImage = Nothing, heightImage = Nothing, descriptionImage = Nothing } -- Category value with default components.. -- defaultCategory :: Category defaultCategory = Category { categoryCategory = error "category missing category", domainCategory = Nothing } -- Items value with default components. -- defaultItem :: Item defaultItem = Item { titleItem = Nothing, linkItem = Nothing, descriptionItem = Nothing, authorItem = Nothing, categoryItem = [], commentsItem = Nothing, enclosureItem = Nothing, guidItem = Nothing, pubDateItem = Nothing, sourceItem = Nothing } -- Enclosure value with default components.. -- defaultEnclosure :: Enclosure defaultEnclosure = Enclosure { urlEnclosure = error "enclosure missing url", lengthEnclosure = error "enclosure missing length", typeEnclosure = error "enclosure missing type" } -- GUID value with default components.. -- defaultGUID :: GUID defaultGUID = GUID { guidGUID = error "guid missing guid", isPermaLinkGUID = Nothing } -- GUID value with default components.. -- defaultSource :: Source defaultSource = Source { sourceSource = error "source missing source", urlSource = error "source missing url" }