diff --git a/apps/example-ssr/README.md b/apps/example-ssr/README.md index ce5ed109..590893bf 100644 --- a/apps/example-ssr/README.md +++ b/apps/example-ssr/README.md @@ -2,4 +2,4 @@ This example app is the same as the other example app in this repository, except with `output: 'server'` in the Astro configuration. -This example application renders the Sanity.io blog using Astro. It shows how to configure the Sanity + Astro integration in `astro.config.mjs`, querying and displaying Sanity content in `src/pages/index.astro` and `src/pages/posts/[slug].astro`, how to render PortableText in `src/components/PortableText.astro`, and how to present Sanity images in `src/components/SanityImage.astro`. \ No newline at end of file +This example application renders the Sanity.io blog using Astro. It shows how to configure the Sanity + Astro integration in `astro.config.mjs`, querying and displaying Sanity content in `src/pages/index.astro` and `src/pages/posts/[slug].astro`, how to render PortableText in `src/components/PortableText.astro`, and how to present Sanity images in `src/components/SanityImage.astro`. diff --git a/apps/example/README.md b/apps/example/README.md index 22380ae9..6054cfeb 100644 --- a/apps/example/README.md +++ b/apps/example/README.md @@ -1,3 +1,3 @@ # Sanity + Astro example app -This example application renders the Sanity.io blog using Astro. It shows how to configure the Sanity + Astro integration in `astro.config.mjs`, querying and displaying Sanity content in `src/pages/index.astro` and `src/pages/posts/[slug].astro`, how to render PortableText in `src/components/PortableText.astro`, and how to present Sanity images in `src/components/SanityImage.astro`. \ No newline at end of file +This example application renders the Sanity.io blog using Astro. It shows how to configure the Sanity + Astro integration in `astro.config.mjs`, querying and displaying Sanity content in `src/pages/index.astro` and `src/pages/posts/[slug].astro`, how to render PortableText in `src/components/PortableText.astro`, and how to present Sanity images in `src/components/SanityImage.astro`. diff --git a/packages/sanity-astro/README.md b/packages/sanity-astro/README.md index 421338fd..aa932397 100644 --- a/packages/sanity-astro/README.md +++ b/packages/sanity-astro/README.md @@ -15,18 +15,18 @@ npx astro add @sanity/astro Configure the integration in your `astro.config.mjs` file. The configuration options are the same as for @sanity/client. ```typescript -import sanityIntegration from '@sanity/astro'; -import { defineConfig } from 'astro/config'; +import sanityIntegration from "@sanity/astro"; +import { defineConfig } from "astro/config"; // https://astro.build/config export default defineConfig({ integrations: [ sanityIntegration({ - projectId: '3do82whm', + projectId: "3do82whm", dataset: "next", - useCdn: true - }) - ] + useCdn: true, + }), + ], }); ``` diff --git a/packages/sanity-astro/index.ts b/packages/sanity-astro/index.ts index c7a9d57c..57d786db 100644 --- a/packages/sanity-astro/index.ts +++ b/packages/sanity-astro/index.ts @@ -1,22 +1,22 @@ -import type { AstroIntegration } from 'astro' -import type { SanityClient, ClientConfig } from '@sanity/client' -import { vitePluginSanityInit } from './vite-plugin-sanity-init' +import type { AstroIntegration } from "astro"; +import type { SanityClient, ClientConfig } from "@sanity/client"; +import { vitePluginSanityInit } from "./vite-plugin-sanity-init"; declare global { - var sanityClientInstance: SanityClient + var sanityClientInstance: SanityClient; } export function useSanityClient(): SanityClient { if (!globalThis.sanityClientInstance) { - console.error('sanityClientInstance has not been initialized correctly') + console.error("sanityClientInstance has not been initialized correctly"); } - return globalThis.sanityClientInstance + return globalThis.sanityClientInstance; } -export type IntegrationOptions = ClientConfig +export type IntegrationOptions = ClientConfig; const defaultOptions: IntegrationOptions = { - apiVersion: 'v2021-03-25', -} + apiVersion: "v2021-03-25", +}; export default function sanityIntegration( options: IntegrationOptions @@ -24,25 +24,25 @@ export default function sanityIntegration( const resolvedOptions = { ...defaultOptions, ...options, - } + }; return { - name: '@sanity/astro', + name: "@sanity/astro", hooks: { - 'astro:config:setup': ({ injectScript, updateConfig }) => { + "astro:config:setup": ({ injectScript, updateConfig }) => { updateConfig({ vite: { plugins: [vitePluginSanityInit(resolvedOptions)], }, - }) + }); injectScript( - 'page-ssr', + "page-ssr", ` import { sanityClientInstance } from "virtual:sanity-init"; globalThis.sanityClientInstance = sanityClientInstance; ` - ) + ); }, }, - } + }; } diff --git a/packages/sanity-astro/vite.config.ts b/packages/sanity-astro/vite.config.ts index afc76356..a27a6be1 100644 --- a/packages/sanity-astro/vite.config.ts +++ b/packages/sanity-astro/vite.config.ts @@ -19,4 +19,4 @@ export default defineConfig(() => { }) as unknown as Plugin, ], }; -}); \ No newline at end of file +});