rsspls icon indicating copy to clipboard operation
rsspls copied to clipboard

Allow the summary selector to match multiple elements

Open wezm opened this issue 1 year ago • 5 comments

All matched elements are used to generate the item description.

Closes #44

wezm avatar Jun 08 '24 05:06 wezm

@doekman any chance you can test this out to see if it works for you?

wezm avatar Jun 08 '24 05:06 wezm

I got Rust running on my computer. The whole process is friction free (wouldn't expect that from rust, LOL).

The results from all found nodes is included, but they always seems to appear in the DOM order. I would like when I change the order of the selectors, the found elements are also included in this order.

In my example: on the original website, an item first shows an image, and below the image are the title and play dates of the movie. I want to show the play dates first in the summary, and after that the image.

So summary = "img, div" should return <img/><div>...</div> and summary = "div, img" should return <div>...</div><img/>.

doekman avatar Jun 08 '24 18:06 doekman

Thanks for testing. I really appreciate that. For the comma based CSS syntax I don't have any control over the order they're matched, since it's done by a library and the behaviour matches browser behaviour. I expect that it traverses the DOM tree and checks if the selector matches (regardless of selector order), yielding matching elements as they are found.

I think in order to support what you need the summary value will need to be able to accept a string or an array of strings so something like:

summary = ["div", "img"]

and rsspls will make a pass through the document for each selector in the order they're defined.

wezm avatar Jun 08 '24 20:06 wezm

I pushed another commit that allows using an array of selectors. @doekman does this allow you to achieve what you wanted? In your original example from #44 this would be specified as:

summary = ["div.jss61", "div img"]

wezm avatar Jun 09 '24 23:06 wezm

Yes, works nicely. I also like the solution by using an array of selectors!

doekman avatar Jun 10 '24 09:06 doekman