I’d love a solution to elegantly handle outputting full paths for all of the assets. I also hope there is something in the works for the blocks implementation that’s being developed so it’s easy to make and serve a headless kirby site.
The problem is that if you only send data instead of rendered HTML to the frontend, you have to do all the parsing yourself, especially if you use Kirbytext or want to make use of Kirby’s resizing and cropping features for files to create responsive images. So the easiest way to solve this would be to send the rendered data in your json response.
But if you only want the data, I guess that is what you want to do all this on the frontend.
The way files work in Kirby, they are copied to the media folder when you call the $file->url() method. So if you only replace your filename with the path to the media folder, then you would get the URL but not the image.
I think you can solve this with your example by looping through your blocks array recursively and replace each filename with the result of $file->url().