@devite/nuxt-sanity 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version][npm-version-src]][npm-version-href]
4
4
 
5
- Optimizes the configuration for [@nuxtjs/sanity][nuxt-sanity] and provides additional helper components.
5
+ Provides additional helper components and utilities for the [Nuxt Sanity Module][nuxt-sanity].
6
6
 
7
7
  ## Quick Setup
8
8
 
@@ -12,7 +12,7 @@ Install the module to your Nuxt application with one command:
12
12
  npx nuxi module add @devite/nuxt-sanity
13
13
  ```
14
14
 
15
- That's it! You can now use the Sanity Integration in your Nuxt app ✨
15
+ That's it! You can now use data from Sanity in your Nuxt app ✨
16
16
 
17
17
 
18
18
  ## Contribution
@@ -22,7 +22,7 @@ That's it! You can now use the Sanity Integration in your Nuxt app ✨
22
22
 
23
23
  ```bash
24
24
  # Install dependencies
25
- pnpm install
25
+ pnpm install && cd playground/cms && pnpm install
26
26
 
27
27
  # Generate type stubs
28
28
  pnpm dev:prepare
package/dist/module.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
3
  "configKey": "@devite/nuxt-sanity",
4
- "version": "1.0.2",
4
+ "version": "1.1.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
- "unbuild": "2.0.0"
7
+ "unbuild": "unknown"
8
8
  }
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { defineNuxtModule, createResolver, addComponentsDir } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addComponentsDir, addImportsDir } from '@nuxt/kit';
2
2
 
3
3
  const module = defineNuxtModule({
4
4
  meta: {
@@ -8,6 +8,7 @@ const module = defineNuxtModule({
8
8
  const { resolve } = createResolver(import.meta.url);
9
9
  await addComponentsDir({ path: resolve("runtime/components") });
10
10
  await addComponentsDir({ path: "~/sanity", global: true, prefix: "Sanity" });
11
+ addImportsDir(resolve("runtime/utils"));
11
12
  }
12
13
  });
13
14
 
@@ -11,10 +11,13 @@
11
11
  <script setup lang="ts">
12
12
  import { useSanityQuery } from '@nuxtjs/sanity/runtime/composables'
13
13
  import { groq } from '@nuxtjs/sanity/runtime/groq'
14
+ import type { ComputedRef } from 'vue'
15
+ import type { ImageAsset } from '@sanity/types'
14
16
  import type { Home } from '../types/singletons/Home'
15
17
  import type { Page } from '../types/documents/Page'
16
18
  import type { NotFound } from '../types/singletons/NotFound'
17
19
  import type { GlobalSEO } from '../types/objects/global/GlobalSEO'
20
+ import { IMAGE_PROJECTION } from '../utils/projections'
18
21
  import { useHead, useRoute, useRuntimeConfig, useSeoMeta } from '#app'
19
22
  import { computed } from '#imports'
20
23
 
@@ -22,13 +25,13 @@ const { baseURL } = useRuntimeConfig().public
22
25
 
23
26
  const path = useRoute().fullPath
24
27
  const groqFilter = path === '/' ? '_type == "home"' : `_type == "page" && slug.current == "${path.substring(1)}"`
25
- const { data: sanityData } = await useSanityQuery<Home | Page | NotFound>(groq`*[(${groqFilter}) || _type == "notFound"][0] { _id, _type, title, modules, seo }`)
28
+ const { data: sanityData } = await useSanityQuery<Home | Page | NotFound>(groq`*[(${groqFilter}) || _type == "notFound"][0] { _id, _type, title, modules, seo { _type, indexable, title, shortTitle, description, image ${IMAGE_PROJECTION} } }`)
26
29
 
27
30
  const seo = computed(() => sanityData.value?.seo)
28
31
  const url = computed(() => baseURL + (sanityData.value?.slug || '/'))
29
32
 
30
- const { data: globalSEO } = await useSanityQuery<GlobalSEO>(groq`*[_type == 'settings'][0].seo { siteName, image }`)
31
- const image = computed(() => sanityData.value?.image || globalSEO.value?.image)
33
+ const { data: globalSEO } = await useSanityQuery<GlobalSEO>(groq`*[_type == 'settings'][0].seo { siteName, image ${IMAGE_PROJECTION} }`)
34
+ const image: ComputedRef<ImageAsset> = computed(() => sanityData.value?.image?.asset || globalSEO.value?.image?.asset)
32
35
 
33
36
  useHead({
34
37
  meta: [
@@ -0,0 +1,3 @@
1
+ export declare const IMAGE_ASSET_PROJECTION: any;
2
+ export declare const IMAGE_WITHOUT_PREVIEW_PROJECTION: any;
3
+ export declare const IMAGE_WITH_PREVIEW_PROJECTION: any;
@@ -0,0 +1,17 @@
1
+ import { groq } from "@nuxtjs/sanity/runtime/groq";
2
+ export const IMAGE_ASSET_PROJECTION = groq`{
3
+ _type,
4
+ _id,
5
+ url,
6
+ altText,
7
+ mimeType,
8
+ metadata { lqip, dimensions }
9
+ }`;
10
+ export const IMAGE_WITHOUT_PREVIEW_PROJECTION = groq`{
11
+ _type,
12
+ asset-> ${IMAGE_ASSET_PROJECTION.replace("lqip, ", "")},
13
+ }`;
14
+ export const IMAGE_WITH_PREVIEW_PROJECTION = groq`{
15
+ _type,
16
+ asset-> ${IMAGE_ASSET_PROJECTION}
17
+ }`;
@@ -0,0 +1,2 @@
1
+ import type { ImageAsset } from '@sanity/types';
2
+ export declare const resolveImageAssetById: (id: string) => Promise<ImageAsset | undefined>;
@@ -0,0 +1,5 @@
1
+ import { useSanityQuery } from "@nuxtjs/sanity/runtime/composables";
2
+ import { IMAGE_ASSET_PROJECTION } from "./projections.js";
3
+ export const resolveImageAssetById = async (id) => {
4
+ return await useSanityQuery(`*[_type == "sanity.imageAsset" && _id == $assetId][0] ${IMAGE_ASSET_PROJECTION}`, { assetId: id });
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Optimizes the configuration for @nuxt/sanity and provides additional helper components.",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",