How do I change the value of a node property and save the new tree #201
-
I'm converting my blog from WordPress to Next.js For each article, I want to download the image and change the This is how far I've gotten with the documentation and my very limited understanding of AST.
Where do I go from here? How do I permanently change the tree? 🙏🏼 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Welcome @mirhamasala! 👋 A couple minor suggestions which may further improve the code (both are incorporated in the sandbox above).
|
Beta Was this translation helpful? Give feedback.
-
Hi @ChristianMurphy ☀️ Thank you. Very clear. And so kind of you to create a Sandbox to show it. ❤️ |
Beta Was this translation helpful? Give feedback.
Welcome @mirhamasala! 👋
You're on the right track, and from a cursory glance I think the code may already work?
Visit allows for changes to be made directly to the tree in place.
I tried it in the rehype sandbox wrapping it as a plugin: https://codesandbox.io/s/zealous-matan-nf9gec?file=/src/index.js and it appeared to work.
A couple minor suggestions which may further improve the code (both are incorporated in the sandbox above).
test
option fromunist-util-visit
to more quickly filter the tree to find the image elements. Something like{ ty…