@devite/nuxt-sanity 1.0.1 → 1.0.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.
Files changed (28) hide show
  1. package/README.md +3 -3
  2. package/dist/module.json +2 -2
  3. package/dist/module.mjs +2 -1
  4. package/dist/runtime/components/SanityComponent.vue +25 -7
  5. package/dist/runtime/components/{link/External.vue → SanityLinkExternal.vue} +1 -1
  6. package/dist/runtime/components/{link/Internal.vue → SanityLinkInternal.vue} +1 -1
  7. package/dist/runtime/components/SanityPage.vue +18 -11
  8. package/dist/runtime/components/{RichText.vue → SanityRichText.vue} +5 -4
  9. package/dist/runtime/types/documents/Page.d.ts +10 -0
  10. package/dist/runtime/types/documents/Page.js +0 -0
  11. package/dist/runtime/types/objects/SEO.d.ts +9 -0
  12. package/dist/runtime/types/objects/SEO.js +0 -0
  13. package/dist/runtime/types/objects/global/GlobalSEO.d.ts +5 -0
  14. package/dist/runtime/types/objects/global/GlobalSEO.js +0 -0
  15. package/dist/runtime/types/objects/link/LinkExternal.d.ts +5 -0
  16. package/dist/runtime/types/objects/link/LinkExternal.js +0 -0
  17. package/dist/runtime/types/objects/link/LinkInternal.d.ts +4 -0
  18. package/dist/runtime/types/objects/link/LinkInternal.js +0 -0
  19. package/dist/runtime/types/richText/RichText.d.ts +2 -0
  20. package/dist/runtime/types/richText/RichText.js +0 -0
  21. package/dist/runtime/types/singletons/Home.d.ts +6 -0
  22. package/dist/runtime/types/singletons/Home.js +0 -0
  23. package/dist/runtime/types/singletons/NotFound.d.ts +6 -0
  24. package/dist/runtime/types/singletons/NotFound.js +0 -0
  25. package/dist/runtime/utils/projections.d.ts +2 -0
  26. package/dist/runtime/utils/projections.js +23 -0
  27. package/package.json +1 -1
  28. /package/dist/runtime/components/{ImageAsset.vue → SanityImageAsset.vue} +0 -0
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.1",
4
+ "version": "1.0.3",
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
 
@@ -9,12 +9,30 @@
9
9
  </template>
10
10
 
11
11
  <script setup lang="ts">
12
- const props = defineProps<{ data: object }>()
12
+ import type { Component } from '@nuxt/schema'
13
+ import { resolveComponent } from '#imports'
14
+ import { SanityLinkExternal, SanityLinkInternal, SanityRichText } from '#components'
13
15
 
14
- const type
15
- = props.data.constructor.name === 'Array' && props.data.every(item => item._type === 'block')
16
- ? 'richText'
17
- : props.data?._type
18
- const upperCamelCase = type?.charAt(0).toUpperCase() + type?.slice(1)
19
- const component = resolveComponent('Sanity' + upperCamelCase)
16
+ const props = defineProps<{ data?: object }>()
17
+
18
+ const type = props.data?._type
19
+ let component: Component
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
+ }
35
+
36
+ break
37
+ }
20
38
  </script>
@@ -8,7 +8,7 @@
8
8
  </template>
9
9
 
10
10
  <script setup lang="ts">
11
- import type { LinkExternal } from '~/types/objects/link/LinkExternal'
11
+ import type { LinkExternal } from '../types/objects/link/LinkExternal'
12
12
 
13
13
  defineProps<{ data: LinkExternal }>()
14
14
  </script>
@@ -7,7 +7,7 @@
7
7
  </template>
8
8
 
9
9
  <script setup lang="ts">
10
- import type { LinkInternal } from '~/types/objects/link/LinkInternal'
10
+ import type { LinkInternal } from '../types/objects/link/LinkInternal'
11
11
 
12
12
  defineProps<{ data: LinkInternal }>()
13
13
  </script>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <main v-if="sanityData.modules?.length > 0">
2
+ <main v-if="sanityData?.modules?.length > 0">
3
3
  <SanityComponent
4
4
  v-for="module in sanityData.modules"
5
5
  :key="module._key"
@@ -9,26 +9,33 @@
9
9
  </template>
10
10
 
11
11
  <script setup lang="ts">
12
- import type { Home } from '~/types/singletons/Home'
13
- import type { Page } from '~/types/documents/Page'
14
- import type { NotFound } from '~/types/singletons/NotFound'
15
- import type { GlobalSEO } from '~/types/objects/global/GlobalSEO'
12
+ import { useSanityQuery } from '@nuxtjs/sanity/runtime/composables'
13
+ import { groq } from '@nuxtjs/sanity/runtime/groq'
14
+ import type { ComputedRef } from 'vue'
15
+ import type { ImageAsset } from '@sanity/types'
16
+ import type { Home } from '../types/singletons/Home'
17
+ import type { Page } from '../types/documents/Page'
18
+ import type { NotFound } from '../types/singletons/NotFound'
19
+ import type { GlobalSEO } from '../types/objects/global/GlobalSEO'
20
+ import { IMAGE_PROJECTION } from '../utils/projections'
21
+ import { useHead, useRoute, useRuntimeConfig, useSeoMeta } from '#app'
22
+ import { computed } from '#imports'
16
23
 
17
24
  const { baseURL } = useRuntimeConfig().public
18
25
 
19
26
  const path = useRoute().fullPath
20
27
  const groqFilter = path === '/' ? '_type == "home"' : `_type == "page" && slug.current == "${path.substring(1)}"`
21
- 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} } }`)
22
29
 
23
30
  const seo = computed(() => sanityData.value?.seo)
24
31
  const url = computed(() => baseURL + (sanityData.value?.slug || '/'))
25
32
 
26
- const { data: globalSEO } = await useSanityQuery<GlobalSEO>(groq`*[_type == 'settings'][0].seo { site_name, image }`)
27
- 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)
28
35
 
29
36
  useHead({
30
37
  meta: [
31
- { name: 'site_name', content: () => globalSEO.value?.site_name },
38
+ { name: 'site_name', content: () => globalSEO.value?.siteName },
32
39
  { name: 'og:image', content: () => image.value?.url },
33
40
  { name: 'og:image:width', content: () => image.value?.metadata.dimensions.width },
34
41
  { name: 'og:image:height', content: () => image.value?.metadata.dimensions.height },
@@ -47,9 +54,9 @@ useSeoMeta({
47
54
  robots: () => ((seo.value?.indexable ? '' : 'no') + 'index,follow'),
48
55
  title: () => seo.value?.title,
49
56
  description: () => seo.value?.description,
50
- ogTitle: () => seo.value?.opengraph_title,
57
+ ogTitle: () => seo.value?.shortTitle,
51
58
  ogDescription: () => seo.value?.description,
52
- twitterTitle: () => seo.value?.opengraph_title,
59
+ twitterTitle: () => seo.value?.shortTitle,
53
60
  twitterDescription: () => seo.value?.description,
54
61
  })
55
62
  </script>
@@ -7,8 +7,9 @@
7
7
 
8
8
  <script setup lang="ts">
9
9
  import { PortableText, type PortableTextComponents } from '@portabletext/vue'
10
- import type { RichText } from '~/types/richText/RichText'
11
- import { LinkExternal, LinkInternal } from '#components'
10
+ import type { RichText } from '../types/richText/RichText'
11
+ import { computed, h } from '#imports'
12
+ import { SanityLinkExternal, SanityLinkInternal } from '#components'
12
13
 
13
14
  const { data, placeholders = {} } = defineProps<{ data: RichText, placeholders?: object }>()
14
15
  const currentData = computed(() => {
@@ -47,9 +48,9 @@ function replacePlaceholders(text: string) {
47
48
  const richTextSerializer: PortableTextComponents = {
48
49
  marks: {
49
50
  linkExternal: ({ value }, { slots }) =>
50
- h(LinkExternal, { data: value }, slots.default),
51
+ h(SanityLinkExternal, { data: value }, slots.default),
51
52
  linkInternal: ({ value }, { slots }) =>
52
- h(LinkInternal, { data: value }, slots.default),
53
+ h(SanityLinkInternal, { data: value }, slots.default),
53
54
  },
54
55
  }
55
56
  </script>
@@ -0,0 +1,10 @@
1
+ import type { Slug } from '@sanity/types';
2
+ import type { SEO } from '../objects/SEO.js';
3
+ export interface Page {
4
+ _id: string;
5
+ _type: 'page';
6
+ title: string;
7
+ slug: Slug;
8
+ modules: Array<object>;
9
+ seo: SEO;
10
+ }
File without changes
@@ -0,0 +1,9 @@
1
+ import type { Image } from '@sanity/types';
2
+ export interface SEO {
3
+ _type: 'seo';
4
+ indexable: boolean;
5
+ title: string;
6
+ shortTitle: string;
7
+ description: string;
8
+ image?: Image;
9
+ }
File without changes
@@ -0,0 +1,5 @@
1
+ import type { Image } from '@sanity/types';
2
+ export interface GlobalSEO {
3
+ siteName: string;
4
+ image: Image;
5
+ }
File without changes
@@ -0,0 +1,5 @@
1
+ export interface LinkExternal {
2
+ _type: 'linkExternal';
3
+ url: string;
4
+ newWindow: boolean;
5
+ }
@@ -0,0 +1,4 @@
1
+ export interface LinkInternal {
2
+ _type: 'linkInternal';
3
+ slug: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ import type { PortableTextBlock } from '@sanity/types';
2
+ export type RichText = PortableTextBlock[];
File without changes
@@ -0,0 +1,6 @@
1
+ import type { SEO } from '../objects/SEO.js';
2
+ export interface Home {
3
+ _type: 'home';
4
+ modules: Array<object>;
5
+ seo: SEO;
6
+ }
File without changes
@@ -0,0 +1,6 @@
1
+ import type { SEO } from '../objects/SEO.js';
2
+ export interface NotFound {
3
+ _type: 'notFound';
4
+ modules: Array<object>;
5
+ seo: SEO;
6
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ export declare const PICTURE_PROJECTION: any;
2
+ export declare const IMAGE_PROJECTION: any;
@@ -0,0 +1,23 @@
1
+ import { groq } from "@nuxtjs/sanity/runtime/groq";
2
+ export const PICTURE_PROJECTION = groq`{
3
+ _type,
4
+ asset-> {
5
+ _type,
6
+ _id,
7
+ url,
8
+ altText,
9
+ mimeType,
10
+ metadata { dimensions }
11
+ }
12
+ }`;
13
+ export const IMAGE_PROJECTION = groq`{
14
+ _type,
15
+ asset-> {
16
+ _type,
17
+ _id,
18
+ url,
19
+ altText,
20
+ mimeType,
21
+ metadata { lqip, dimensions }
22
+ }
23
+ }`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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",