From a1c177517657929c09232178a188a6e4f261f60f Mon Sep 17 00:00:00 2001 From: Simeon Griggs Date: Wed, 30 Oct 2024 16:37:25 +0100 Subject: [PATCH] feat(cli): prepare nextjs starter template for live mode (#7633) Co-authored-by: Espen Hovlandsdal --- .../init-project/templates/nextjs/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts b/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts index bfbdd0c6b4b..32eda6e6b42 100644 --- a/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts +++ b/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts @@ -165,6 +165,21 @@ export const client = createClient({ }) ` +const live = `// Querying with "sanityFetch" will keep content automatically updated +// Before using it, import and render "" in your layout, see +// https://github.com/sanity-io/next-sanity#live-content-api for more information. +import { defineLive } from "next-sanity"; +import { client } from './client' + +export const { sanityFetch, SanityLive } = defineLive({ + client: client.withConfig({ + // Live content is currently only available on the experimental API + // https://www.sanity.io/docs/api-versioning + apiVersion: 'vX' + }) +}); +` + const imageTS = `import createImageUrlBuilder from '@sanity/image-url' import { SanityImageSource } from "@sanity/image-url/lib/types/types"; @@ -201,6 +216,7 @@ export const sanityFolder = ( 'env.': useTypeScript ? envTS : envJS, 'lib': { 'client.': client, + 'live.': live, 'image.': useTypeScript ? imageTS : imageJS, }, }