Open anewuser opened 1 year ago
That would be linked to https://github.com/pipes-digital/pipes/issues/92.
Simple problem: I don't know how to do this properly. Nokogiri does not have an API to create an XML element at a random position via an xpath. At least I did not see a proper solution.
So the code would devolve to something like: Split the xpath at /
, always append one element more together until the xpath does not find the element, then create the children for all subsequent parts of the xpath. That felt so brittle that it gave me pause.
Do you see a better solution?
Doesn't .add_next_sibling work with XPath results?
If it does, what about following this logic:
if xpath(target) exists
execute current code
elseif target matches '^\/(rss)?\/(channel)?\/(item)?\/(category|content:encoded|description|title)$'
xpath('/rss/channel/item/link').add_next_sibling '<replace>content</replace>'
I think it's a good idea to hardcode the accepted tags to prevent abuse or random errors. That's why I said "basic elements" in the title of this issue.
Note: I just deleted a comment where I understood your suggestion wrong. Your idea to limit it to specific items could make this work. There is no reason not to have them in our output feed anyway. Could be automated whenever a RSS feed is generated. I dislike that it's not a general solution, but it should solve the reported usecase.
Could be automated whenever a RSS feed is generated.
This was actually going to be my next suggestion. If the feed
block adds the missing basic elements to all items automatically, we'll be able to keep all items in a problematic feed without having to recreate or truncate the whole feed just to insert the missing element.
What about using the date as a placeholder title in case there's no title? With #71, it'd be even easier to customize each title afterwards. If there's no date either, maybe the link.
Elements like categories, if appended automatically, should be empty by default.
See this example: https://www.pipes.digital/pipe/E9D7p4qj
If you set the
insert
block to target/rss/channel/item/description
, it successfully replaces the existing description.However, if you target
/rss/channel/item/title
, nothing happens, since the post has notitle
tag yet.