Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create missing basic elements with "Insert" #110

Open
anewuser opened this issue Aug 2, 2022 · 4 comments
Open

Create missing basic elements with "Insert" #110

anewuser opened this issue Aug 2, 2022 · 4 comments

Comments

@anewuser
Copy link
Contributor

anewuser commented Aug 2, 2022

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 no title tag yet.

@onli
Copy link
Member

onli commented Aug 2, 2022

That would be linked to #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?

@anewuser
Copy link
Contributor Author

anewuser commented Aug 2, 2022

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.

@onli
Copy link
Member

onli commented Aug 6, 2022

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.

@anewuser
Copy link
Contributor Author

anewuser commented Aug 7, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants