module Text.RSS.Extensions.Content
(
ContentModule(..)
, RssChannelExtension(ContentChannel)
, RssItemExtension(ContentItem)
, contentEncoded
, namespacePrefix
, namespaceURI
) where
import Text.RSS.Extensions
import Text.RSS.Types
import Conduit hiding (throwM)
import Control.Exception.Safe as Exception
import Data.Maybe
import Data.Singletons
import Data.Text
import Data.XML.Types
import GHC.Generics
import Text.XML.Stream.Parse
import URI.ByteString
data ContentModule :: *
data instance Sing ContentModule = SContentModule
instance SingI ContentModule where sing = SContentModule
instance ParseRssExtension ContentModule where
parseRssChannelExtension = pure ContentChannel
parseRssItemExtension = ContentItem <$> (manyYield' contentEncoded =$= headDefC mempty)
data instance RssChannelExtension ContentModule = ContentChannel deriving(Eq, Generic, Ord, Show)
data instance RssItemExtension ContentModule = ContentItem { itemContent :: Text }
deriving(Eq, Generic, Ord, Show)
namespacePrefix :: Text
namespacePrefix = "content"
namespaceURI :: URIRef Absolute
namespaceURI = uri where Right uri = parseURI laxURIParserOptions "http://purl.org/rss/1.0/modules/content/"
contentName :: Text -> Name
contentName string = Name string (Just "http://purl.org/rss/1.0/modules/content/") (Just namespacePrefix)
contentEncoded :: MonadThrow m => ConduitM Event o m (Maybe Text)
contentEncoded = tagIgnoreAttrs (matching (== contentName "encoded")) content