@devite/nuxt-sanity 1.1.1 → 1.1.3

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
3
  "configKey": "@devite/nuxt-sanity",
4
- "version": "1.1.1",
4
+ "version": "1.1.3",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "unknown"
@@ -10,29 +10,29 @@
10
10
 
11
11
  <script setup lang="ts">
12
12
  import type { Component } from '@nuxt/schema'
13
- import { resolveComponent } from '#imports'
13
+ import { computed, resolveComponent } from '#imports'
14
14
  import { SanityLinkExternal, SanityLinkInternal, SanityRichText } from '#components'
15
15
 
16
- const props = defineProps<{ data?: object }>()
16
+ const { data } = defineProps<{ data?: object }>()
17
17
 
18
- const type = props.data?._type
19
- let component: Component
18
+ const component = computed<Component>(() => {
19
+ const type = data?._type
20
20
 
21
- switch (type) {
22
- case 'linkInternal':
23
- component = SanityLinkInternal
24
- break
25
- case 'linkExternal':
26
- component = SanityLinkExternal
27
- break
28
- default:
29
- if (props.data?.constructor.name === 'Array' && props.data.every(item => item._type === 'block'))
30
- component = SanityRichText
31
- else if (type) {
32
- const upperCamelCase = type.charAt(0).toUpperCase() + type.slice(1)
33
- component = resolveComponent('Sanity' + upperCamelCase)
34
- }
21
+ switch (type) {
22
+ case 'linkInternal':
23
+ return SanityLinkInternal
24
+ case 'linkExternal':
25
+ return SanityLinkExternal
26
+ default:
27
+ if (data?.constructor.name === 'Array' && data.every(item => item._type === 'block'))
28
+ return SanityRichText
29
+ else if (type) {
30
+ const upperCamelCase = type.charAt(0).toUpperCase() + type.slice(1)
35
31
 
36
- break
37
- }
32
+ return resolveComponent('Sanity' + upperCamelCase)
33
+ }
34
+ }
35
+
36
+ return null
37
+ })
38
38
  </script>
@@ -24,24 +24,26 @@ import { computed } from '#imports'
24
24
  const { baseURL } = useRuntimeConfig().public
25
25
 
26
26
  const path = useRoute().fullPath
27
- const groqFilter = path === '/' ? '_type == "home"' : `_type == "page" && slug.current == "${path.substring(1)}"`
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_WITHOUT_PREVIEW_PROJECTION} } }`)
27
+ const groqFilter = path === '/' ? '_type == "home"' : `_type == "page" && slug.current == $slug`
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_WITHOUT_PREVIEW_PROJECTION} } }`, { slug: path.substring(1) })
29
29
 
30
30
  const seo = computed(() => sanityData.value?.seo)
31
31
  const url = computed(() => baseURL + (sanityData.value?.slug || '/'))
32
32
 
33
33
  const { data: globalSEO } = await useSanityQuery<GlobalSEO>(groq`*[_type == 'settings'][0].seo { siteName, image ${IMAGE_WITHOUT_PREVIEW_PROJECTION} }`)
34
34
  const image: ComputedRef<ImageAsset> = computed(() => sanityData.value?.image?.asset || globalSEO.value?.image?.asset)
35
+ const imageUrl = computed(() => image.value?.url)
36
+ const imageDimensions = computed(() => image.value?.metadata.dimensions)
35
37
 
36
38
  useHead({
37
39
  meta: [
38
40
  { name: 'site_name', content: () => globalSEO.value?.siteName },
39
- { name: 'og:image', content: () => image.value?.url },
40
- { name: 'og:image:width', content: () => image.value?.metadata.dimensions.width },
41
- { name: 'og:image:height', content: () => image.value?.metadata.dimensions.height },
42
- { name: 'twitter:image', content: () => image.value?.url },
43
- { name: 'twitter:image:width', content: () => image.value?.metadata.dimensions.width },
44
- { name: 'twitter:image:height', content: () => image.value?.metadata.dimensions.height },
41
+ { name: 'og:image', content: () => imageUrl.value },
42
+ { name: 'og:image:width', content: () => imageDimensions.value?.width },
43
+ { name: 'og:image:height', content: () => imageDimensions.value?.height },
44
+ { name: 'twitter:image', content: () => imageUrl.value },
45
+ { name: 'twitter:image:width', content: () => imageDimensions.value?.width },
46
+ { name: 'twitter:image:height', content: () => imageDimensions.value?.height },
45
47
  { name: 'og:url', content: () => url.value },
46
48
  { name: 'twitter:url', content: () => url.value },
47
49
  ],
@@ -51,7 +53,7 @@ useHead({
51
53
  })
52
54
 
53
55
  useSeoMeta({
54
- robots: () => ((seo.value?.indexable ? '' : 'no') + 'index,follow'),
56
+ robots: () => `${seo.value?.indexable ? '' : 'no'}index,follow`,
55
57
  title: () => seo.value?.title,
56
58
  description: () => seo.value?.description,
57
59
  ogTitle: () => seo.value?.shortTitle,
@@ -1,5 +1,5 @@
1
1
  import { useSanityQuery } from "@nuxtjs/sanity/runtime/composables";
2
2
  import { IMAGE_ASSET_PROJECTION } from "./projections.js";
3
3
  export const resolveImageAssetById = async (id) => {
4
- return await useSanityQuery(`*[_type == "sanity.imageAsset" && _id == $assetId][0] ${IMAGE_ASSET_PROJECTION}`, { assetId: id });
4
+ return (await useSanityQuery(`*[_type == "sanity.imageAsset" && _id == $assetId][0] ${IMAGE_ASSET_PROJECTION}`, { assetId: id })).data.value;
5
5
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "1.1.1",
4
- "description": "Optimizes the configuration for @nuxt/sanity and provides additional helper components.",
3
+ "version": "1.1.3",
4
+ "description": "Provides additional helper components and utilities for the Nuxt.js Sanity module",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",
7
7
  "author": {