Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Contentstack Kickstart: Astro SSR
# Contentstack Kickstart: Astro

Contentstack Kickstarts are the minimum amount of code needed to connect to Contentstack.
This kickstart covers the following items:

- SDK initialization
- Live preview and Visual building setup

> This example has Contentstack Live preview set up SSR mode turnt on. Which means Contentstack adds query parameters to the URL which we grab in the code and give to the Live Preview SDK intance. Contentstack refreshes the browser on content edit each time.
> This example uses Astro's default static output and runs Contentstack Live Preview in client-side (CSR) mode. Pages are rendered at build time with published content; inside the Visual Builder the Live Preview SDK re-fetches the entry in the browser and re-renders the page on every edit — no server and no iframe refresh needed.

More details about this codebase can be found on the [Contentstack docs](https://www.contentstack.com/docs/developers).

Expand Down Expand Up @@ -75,6 +75,19 @@ PUBLIC_CONTENTSTACK_ENVIRONMENT=preview
PUBLIC_CONTENTSTACK_PREVIEW=true
```

### How live preview updates work

Live preview runs in client-side (CSR) mode: the Live Preview SDK is initialized with `ssr: false`, changes arrive in the browser via postMessage, and the page re-fetches the entry with the Delivery SDK and re-renders client-side — no iframe refresh. See `src/lib/renderPage.ts` for the client-side renderer.

### Timeline support

[Timeline](https://www.contentstack.com/docs/content-managers/timeline/preview-content-across-a-timeline) (previewing your site as it will look at a future date, with scheduled Releases applied) works out of the box:

- Timeline loads the site with `preview_timestamp` and `release_id` query params. The Delivery SDK picks these up automatically and sends them as headers to the Preview API, and `syncPreviewParams` in `src/lib/contentstack.ts` keeps them applied on every client-side re-fetch.
- Timeline's compare view (diff highlighting) relies on the `data-cslp` edit tags, which the client-side renderer preserves.

To use it, enable Timeline for your stack and schedule content with Releases. No code changes needed.

## Turn on Live Preview

Go to Settings > Live Preview. Click enable and select the `Preview` environment in the drop down. Hit save.
Expand Down
6 changes: 0 additions & 6 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
// @ts-check
import { defineConfig } from "astro/config";
import tailwindcss from "@tailwindcss/vite";
import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
output: "server",
adapter: node({
mode: "standalone"
}),
vite: {
// @ts-ignore - tailwindcss plugin type compatibility
plugins: [tailwindcss()],
resolve: {
extensions: ['.js', '.mjs', '.ts', '.jsx', '.tsx', '.json'],
Expand Down
384 changes: 384 additions & 0 deletions docs/astro.md

Large diffs are not rendered by default.

Loading
Loading