@devite/nuxt-sanity 1.1.2 → 1.2.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/dist/module.json +1 -1
- package/dist/runtime/components/SanityComponent.vue +20 -20
- package/dist/runtime/components/SanityImageAsset.vue +9 -8
- package/dist/runtime/components/SanityPage.vue +11 -9
- package/dist/runtime/utils/resolveImageAssetById.d.ts +2 -1
- package/dist/runtime/utils/resolveImageAssetById.js +1 -1
- package/package.json +9 -7
package/dist/module.json
CHANGED
|
@@ -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
|
|
16
|
+
const { data } = defineProps<{ data?: object }>()
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const component = computed<Component>(() => {
|
|
19
|
+
const type = data?._type
|
|
20
20
|
|
|
21
|
-
switch (type) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
37
|
-
}
|
|
32
|
+
return resolveComponent('Sanity' + upperCamelCase)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return null
|
|
37
|
+
})
|
|
38
38
|
</script>
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<NuxtImg
|
|
3
|
-
v-if="
|
|
3
|
+
v-if="imageAsset?._id"
|
|
4
4
|
densities="x1 x2"
|
|
5
|
-
:src="
|
|
6
|
-
:width="
|
|
7
|
-
:height="
|
|
8
|
-
:alt="
|
|
9
|
-
:placeholder="
|
|
5
|
+
:src="imageAsset._id"
|
|
6
|
+
:width="imageAsset.metadata.dimensions.width"
|
|
7
|
+
:height="imageAsset.metadata.dimensions.height"
|
|
8
|
+
:alt="imageAsset.altText"
|
|
9
|
+
:placeholder="imageAsset.metadata.lqip"
|
|
10
10
|
:loading="loading"
|
|
11
|
-
:format="
|
|
11
|
+
:format="imageAsset.mimeType === 'image/svg+xml' ? undefined : 'webp'"
|
|
12
12
|
draggable="false"
|
|
13
13
|
/>
|
|
14
14
|
</template>
|
|
@@ -16,5 +16,6 @@
|
|
|
16
16
|
<script setup lang="ts">
|
|
17
17
|
import type { ImageAsset } from '@sanity/types'
|
|
18
18
|
|
|
19
|
-
const { loading = 'lazy' } = defineProps<{ asset
|
|
19
|
+
const { asset, loading = 'lazy' } = defineProps<{ asset?: ImageAsset, loading?: 'lazy' | 'eager' }>()
|
|
20
|
+
const imageAsset = asset?._ref ? await resolveImageAssetById(asset._ref) : asset
|
|
20
21
|
</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 ==
|
|
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: () =>
|
|
40
|
-
{ name: 'og:image:width', content: () =>
|
|
41
|
-
{ name: 'og:image:height', content: () =>
|
|
42
|
-
{ name: 'twitter:image', content: () =>
|
|
43
|
-
{ name: 'twitter:image:width', content: () =>
|
|
44
|
-
{ name: 'twitter:image:height', content: () =>
|
|
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: () =>
|
|
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,2 +1,3 @@
|
|
|
1
1
|
import type { ImageAsset } from '@sanity/types';
|
|
2
|
-
|
|
2
|
+
import type { Ref } from '#imports';
|
|
3
|
+
export declare const resolveImageAssetById: (id: string) => Promise<Ref<ImageAsset | undefined>>;
|
|
@@ -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 })).data
|
|
4
|
+
return (await useSanityQuery(`*[_type == "sanity.imageAsset" && _id == $assetId][0] ${IMAGE_ASSET_PROJECTION}`, { assetId: id })).data;
|
|
5
5
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devite/nuxt-sanity",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.0",
|
|
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": {
|
|
@@ -22,20 +22,22 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@nuxt/image": "^1.8.0",
|
|
25
26
|
"@nuxt/kit": "^3.13.2",
|
|
26
27
|
"@nuxtjs/sanity": "^1.12.1",
|
|
27
|
-
"@
|
|
28
|
+
"@portabletext/vue": "^1.0.11",
|
|
29
|
+
"@sanity/client": "^6.22.0",
|
|
30
|
+
"@sanity/types": "^3.59.0"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
|
-
"@nuxt/devtools": "^1.
|
|
33
|
+
"@nuxt/devtools": "^1.5.1",
|
|
31
34
|
"@nuxt/eslint-config": "^0.5.7",
|
|
32
35
|
"@nuxt/module-builder": "^0.8.4",
|
|
33
36
|
"@nuxt/schema": "^3.13.2",
|
|
34
37
|
"@nuxt/test-utils": "^3.14.2",
|
|
35
|
-
"@portabletext/vue": "^1.0.11",
|
|
36
38
|
"@types/node": "latest",
|
|
37
|
-
"changelogen": "^0.5.
|
|
38
|
-
"eslint": "^9.
|
|
39
|
+
"changelogen": "^0.5.7",
|
|
40
|
+
"eslint": "^9.11.1",
|
|
39
41
|
"nuxt": "^3.13.2",
|
|
40
42
|
"typescript": "latest",
|
|
41
43
|
"vitest": "^2.1.1",
|