@devite/nuxt-sanity 2.4.0 → 2.4.2
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
package/dist/module.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { defineNuxtModule, createResolver, addPlugin, addServerHandler, addImpor
|
|
|
3
3
|
import defu from 'defu';
|
|
4
4
|
|
|
5
5
|
const name = "@devite/nuxt-sanity";
|
|
6
|
-
const version = "2.4.
|
|
6
|
+
const version = "2.4.2";
|
|
7
7
|
|
|
8
8
|
const CONFIG_KEY = "sanity";
|
|
9
9
|
const module = defineNuxtModule({
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
import { computed, type ComputedRef } from 'vue'
|
|
13
13
|
import type { ImageAsset } from '@sanity/types'
|
|
14
14
|
import type { GlobalSEO, Home, NotFound, Page } from '@devite/nuxt-sanity'
|
|
15
|
+
import { setResponseStatus } from 'h3'
|
|
15
16
|
import { IMAGE_WITHOUT_PREVIEW_PROJECTION } from '../utils/projections'
|
|
16
17
|
import { useSanityQuery } from '../composables/useSanityQuery'
|
|
17
18
|
import { groq } from '../utils/groq'
|
|
18
|
-
import { useHead, useRoute, useRuntimeConfig, useSeoMeta } from '#imports'
|
|
19
|
+
import { useHead, useRoute, useRuntimeConfig, useSeoMeta, useRequestEvent } from '#imports'
|
|
19
20
|
|
|
20
21
|
const path = useRoute().path
|
|
21
22
|
const groqFilter = path === '/' ? '_type == "home"' : `_type == "page" && slug.current == $slug`
|
|
@@ -24,6 +25,13 @@ const { data: sanityData } = await useSanityQuery<Home | Page | NotFound>(
|
|
|
24
25
|
{ slug: path.substring(1) },
|
|
25
26
|
)
|
|
26
27
|
|
|
28
|
+
if (sanityData.value?._type === 'notFound' && import.meta.server) {
|
|
29
|
+
const event = useRequestEvent()
|
|
30
|
+
|
|
31
|
+
if (event)
|
|
32
|
+
setResponseStatus(event, 404)
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
const { baseURL } = useRuntimeConfig().public
|
|
28
36
|
const seo = computed(() => sanityData.value?.seo)
|
|
29
37
|
const url = computed(
|
|
@@ -39,6 +39,9 @@ export default defineEventHandler(async (event) => {
|
|
|
39
39
|
);
|
|
40
40
|
if (!result)
|
|
41
41
|
throw createError({ statusCode: 400, statusMessage: "Invalid query" });
|
|
42
|
+
setResponseHeader(event, "Content-Type", "application/json");
|
|
43
|
+
if (Object.keys(result).length === 0)
|
|
44
|
+
return {};
|
|
42
45
|
await dataCache.setItem(hashedQuery, result, { ttl: TTL });
|
|
43
46
|
const stringifiedResult = JSON.stringify(result);
|
|
44
47
|
const referencedIds = stringifiedResult.match(/"(_ref|_id)":\s*"(.*?)"/g) || [];
|
|
@@ -53,7 +56,6 @@ export default defineEventHandler(async (event) => {
|
|
|
53
56
|
});
|
|
54
57
|
})));
|
|
55
58
|
}
|
|
56
|
-
setResponseHeader(event, "Content-Type", "application/json");
|
|
57
59
|
if (import.meta.dev) {
|
|
58
60
|
console.debug(`Cache miss for query ${hashedQuery} (${referencedIds.join(", ")})`);
|
|
59
61
|
}
|