Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(prettier): πŸ€– ✨ #2

Merged
merged 1 commit into from
Aug 9, 2023
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
2 changes: 1 addition & 1 deletion apps/example-ssr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
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`.
2 changes: 1 addition & 1 deletion apps/example/README.md
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`.
12 changes: 6 additions & 6 deletions packages/sanity-astro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
],
});
```

Expand Down
32 changes: 16 additions & 16 deletions packages/sanity-astro/index.ts
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;
`
)
);
},
},
}
};
}
2 changes: 1 addition & 1 deletion packages/sanity-astro/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export default defineConfig(() => {
}) as unknown as Plugin,
],
};
});
});