Git Product home page Git Product logo

Comments (6)

k0ral avatar k0ral commented on August 26, 2024

You are right, this is a preposterous omission that I'll fix immediately.

from rss-conduit.

k0ral avatar k0ral commented on August 26, 2024

Fixed in bfd53ae . Released as 0.3.1.2. Could you please confirm it works now ?

from rss-conduit.

wyager avatar wyager commented on August 26, 2024

Alright, just had to bump to lts-9.0 and rebuild. Let's see...

Looks good! Thank you. Will report any other issues.

A couple things I notice that I don't think are bugs but are a bit unexpected is that

A) the URI formatter doesn't insert '://' between the scheme and location, but instead just ':'. This may be correct, I'm not sure. I know some URI schemes are like that. It just means I have to prepend all locations with '//'.

and B) the output doesn't start with the <?xml version=...?> header, but that's obviously easily rectified.

I'm going to close this issue, and if either of those things sound incorrect, feel free to open a different one.

from rss-conduit.

k0ral avatar k0ral commented on August 26, 2024

Could you please provide a reproducible example for issue A) ?

Regarding B), this is intended behavior: renderRssDocument doesn't render an XML document, it renders an RSS document, and there's no reason to assume that these scopes are identical. Users should be able to render an XML document including multiple RSS documents, if they wish so.
The top-level XML declaration <?xml version=...?> is supposed to be rendered by functions renderBuilder/renderText/renderBytes from module Text.XML.Stream.Render (in xml-conduit package).

from rss-conduit.

wyager avatar wyager commented on August 26, 2024

Hmm, renderBuilder doesn't seem to do that for me... No problem though, I'm just accumulating the builders via a fold, so making the initial element a builder containing the XML tag produces the desired output.

As for A, here's a stripped-down version of my code. Look at the definition of https:

{-# LANGUAGE OverloadedLists, OverloadedStrings #-}
module Main where

import Data.Monoid (mempty, (<>))
import qualified Data.ByteString as B
import qualified Data.Text as T
import qualified Text.RSS.Types as RSST
import qualified Text.RSS.Conduit.Render as RSSR
import qualified Text.XML.Stream.Render as XMLR
import qualified Data.Conduit.List as CL
import qualified URI.ByteString as URIB
import qualified Data.Time.Clock as Clock
import qualified Data.Time.Calendar as Calendar
import           Data.Conduit (ConduitM, runConduit, (=$=))
import           Data.Void (Void)
import           Control.Monad.Identity (Identity, runIdentity)
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Lazy as BL


main = BL.putStrLn (renderFeed feed)

feed :: RSST.RssDocument
feed = RSST.RssDocument {
        RSST.documentVersion = [2,0],
        RSST.channelTitle = "Title",
        RSST.channelLink = https "example.com",
        RSST.channelDescription = "foo",
        RSST.channelItems = [item],
        RSST.channelLanguage = "en-US",
        RSST.channelCopyright = "Copyright 1999",
        RSST.channelManagingEditor = "Bob Bar",
        RSST.channelWebmaster = "Bill Baz",
        RSST.channelPubDate = Just today,
        RSST.channelLastBuildDate = Just today,
        RSST.channelCategories = categories,
        RSST.channelGenerator = "AbstractRSSAdapterFactoryBean 2.7",
        RSST.channelDocs = Nothing,
        RSST.channelCloud = Nothing,
        RSST.channelTtl = Just 60, -- minutes
        RSST.channelImage = Nothing,
        RSST.channelRating = "Inappropriate for all ages",
        RSST.channelTextInput = Nothing,
        RSST.channelSkipHours = mempty,
        RSST.channelSkipDays = mempty
    }
    where
    today = Clock.UTCTime {Clock.utctDay = Calendar.fromGregorian 3000 8 12, Clock.utctDayTime = 0}
    categories = [RSST.RssCategory "Foo" "Bar"]

item = RSST.RssItem {
        RSST.itemTitle = "My Item",
        RSST.itemLink = Just (https "example.com/item1"),
        RSST.itemDescription = "Some stuff",
        RSST.itemAuthor = "[email protected]",
        RSST.itemCategories = [],
        RSST.itemComments = Nothing,
        RSST.itemEnclosure = [],
        RSST.itemGuid = Just (RSST.GuidText "12345"),
        RSST.itemPubDate = Just (Clock.UTCTime {Clock.utctDay = Calendar.fromGregorian 2020 1 1, Clock.utctDayTime = 0}) ,
        RSST.itemSource = Nothing
    }

renderFeed :: RSST.RssDocument -> BL.ByteString 
renderFeed = BB.toLazyByteString . runIdentity . runConduit . builder
    where
    builder :: RSST.RssDocument -> ConduitM () Void Identity BB.Builder
    builder feed = RSSR.renderRssDocument feed 
               =$= XMLR.renderBuilder (XMLR.def {XMLR.rsPretty = True}) 
               =$= CL.fold (<>) "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"

https :: B.ByteString -> RSST.RssURI
https link = RSST.RssURI (URIB.URI (URIB.Scheme "https") Nothing ("//" <> link) (URIB.Query []) Nothing)

from rss-conduit.

k0ral avatar k0ral commented on August 26, 2024

I just realized I forgot to answer A), my bad.
I suggest you use the quasi-quoters provided in URI.ByteString.QQ. I've been using them in the unit tests for rss-conduit and haven't had any issue with the // characters.

from rss-conduit.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.