-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96cedd8
commit 25e67d8
Showing
5 changed files
with
25 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. | ||
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
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 | ||
): AstroIntegration { | ||
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; | ||
` | ||
) | ||
); | ||
}, | ||
}, | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ export default defineConfig(() => { | |
}) as unknown as Plugin, | ||
], | ||
}; | ||
}); | ||
}); |