Live previews for astro.js

Is it possible to have live previews if my project on astro.js?

Hey Petro, great question. Do you mean the live slice previews in the page builder? Or the full page preview feature that lets you view the full website with updated content?

For the Live Slice Previews in the Page builder, the answer right now is no, you can't get those right now with an Astro project. We're looking into potentially supporting Astro with this in the future, but it's not something we currently support.

For full page website previews, we don't currently have an Astro adapter/solution, but if you want to engineer one you can look at the SvelteKit SDK and how that handles previews. You might be able to engineer a solution from that.

Again, we're looking at potentially supporting Astro with an SDK in the future, and I'm always happy to hear about interest around it because it helps us make decisions on where to put our resources. Thanks for the question!

Ok.
One more question:
When I'm getting data from cookies, is my result for display here "response.results.data.body"?

Hey Petro, I think what you're asking how you can get the cookie from Prismic when fetching, right?

I spoke with our dev @angeloashmore who worked on the SDK for SvelteKit and this is what you should do to get the cookie in your Astro project:

import * as prismic from "@prismicio/client"

const client = prismic.createClient("example-prismic-repo")
client.queryContentFromRef(Astro.cookies.get(prismic.cookie.preview))

const documents = await client.getAllByType("page")

The client.queryContentFromRef(Astro.cookies.get(prismic.cookie.preview)) line will automatically switch between master and the preview ref depending on the cookie's presence.

1 Like