@devite/nuxt-sanity 1.0.1
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +5 -0
- package/dist/module.d.ts +5 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +14 -0
- package/dist/runtime/components/ImageAsset.vue +20 -0
- package/dist/runtime/components/RichText.vue +55 -0
- package/dist/runtime/components/SanityComponent.vue +20 -0
- package/dist/runtime/components/SanityPage.vue +55 -0
- package/dist/runtime/components/link/External.vue +14 -0
- package/dist/runtime/components/link/Internal.vue +13 -0
- package/dist/types.d.mts +7 -0
- package/dist/types.d.ts +7 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Justus Geramb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Nuxt Sanity Integration
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
|
|
5
|
+
Optimizes the configuration for [@nuxtjs/sanity][nuxt-sanity] and provides additional helper components.
|
|
6
|
+
|
|
7
|
+
## Quick Setup
|
|
8
|
+
|
|
9
|
+
Install the module to your Nuxt application with one command:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx nuxi module add @devite/nuxt-sanity
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
That's it! You can now use the Sanity Integration in your Nuxt app ✨
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Contribution
|
|
19
|
+
|
|
20
|
+
<details>
|
|
21
|
+
<summary>Local development</summary>
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Install dependencies
|
|
25
|
+
pnpm install
|
|
26
|
+
|
|
27
|
+
# Generate type stubs
|
|
28
|
+
pnpm dev:prepare
|
|
29
|
+
|
|
30
|
+
# Develop with the playground
|
|
31
|
+
pnpm dev
|
|
32
|
+
|
|
33
|
+
# Build the playground
|
|
34
|
+
pnpm dev:build
|
|
35
|
+
|
|
36
|
+
# Run ESLint
|
|
37
|
+
pnpm lint
|
|
38
|
+
|
|
39
|
+
# Run Vitest
|
|
40
|
+
pnpm test
|
|
41
|
+
pnpm test:watch
|
|
42
|
+
|
|
43
|
+
# Release new version
|
|
44
|
+
pnpm release
|
|
45
|
+
```
|
|
46
|
+
</details>
|
|
47
|
+
|
|
48
|
+
<!-- Links -->
|
|
49
|
+
[nuxt-sanity]: https://github.com/nuxt-modules/sanity
|
|
50
|
+
|
|
51
|
+
<!-- Badges -->
|
|
52
|
+
[npm-version-src]: https://img.shields.io/npm/v/@devite/nuxt-sanity/latest.svg?style=flat&colorA=020420&colorB=00DC82
|
|
53
|
+
[npm-version-href]: https://npmjs.com/package/@devite/nuxt-sanity
|
package/dist/module.cjs
ADDED
package/dist/module.d.ts
ADDED
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponentsDir } from '@nuxt/kit';
|
|
2
|
+
|
|
3
|
+
const module = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "@devite/nuxt-sanity"
|
|
6
|
+
},
|
|
7
|
+
async setup(_options, _nuxt) {
|
|
8
|
+
const { resolve } = createResolver(import.meta.url);
|
|
9
|
+
await addComponentsDir({ path: resolve("runtime/components") });
|
|
10
|
+
await addComponentsDir({ path: "~/sanity", global: true, prefix: "Sanity" });
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export { module as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<NuxtImg
|
|
3
|
+
v-if="asset?._id"
|
|
4
|
+
densities="x1 x2"
|
|
5
|
+
:src="asset._id"
|
|
6
|
+
:width="asset.metadata.dimensions.width"
|
|
7
|
+
:height="asset.metadata.dimensions.height"
|
|
8
|
+
:alt="asset.altText"
|
|
9
|
+
:placeholder="asset.metadata.lqip"
|
|
10
|
+
:loading="loading"
|
|
11
|
+
:format="asset.mimeType === 'image/svg+xml' ? undefined : 'webp'"
|
|
12
|
+
draggable="false"
|
|
13
|
+
/>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script setup lang="ts">
|
|
17
|
+
import type { ImageAsset } from '@sanity/types'
|
|
18
|
+
|
|
19
|
+
const { loading = 'lazy' } = defineProps<{ asset: ImageAsset, loading?: 'lazy' | 'eager' }>()
|
|
20
|
+
</script>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<PortableText
|
|
3
|
+
:value="currentData"
|
|
4
|
+
:components="richTextSerializer"
|
|
5
|
+
/>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { PortableText, type PortableTextComponents } from '@portabletext/vue'
|
|
10
|
+
import type { RichText } from '~/types/richText/RichText'
|
|
11
|
+
import { LinkExternal, LinkInternal } from '#components'
|
|
12
|
+
|
|
13
|
+
const { data, placeholders = {} } = defineProps<{ data: RichText, placeholders?: object }>()
|
|
14
|
+
const currentData = computed(() => {
|
|
15
|
+
return data.map((block) => {
|
|
16
|
+
return {
|
|
17
|
+
...block,
|
|
18
|
+
children: replaceChildren(block.children),
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
function replaceChildren(children: object[]) {
|
|
24
|
+
return children.map((child) => {
|
|
25
|
+
if (child._type === 'span') {
|
|
26
|
+
return {
|
|
27
|
+
...child,
|
|
28
|
+
text: replacePlaceholders(child.text),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (child.children) {
|
|
33
|
+
return {
|
|
34
|
+
...child,
|
|
35
|
+
children: replaceChildren(child.children),
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return child
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function replacePlaceholders(text: string) {
|
|
44
|
+
return text.replace(/\{\{(.*?)\}\}/g, (match, key) => placeholders[key] || match)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const richTextSerializer: PortableTextComponents = {
|
|
48
|
+
marks: {
|
|
49
|
+
linkExternal: ({ value }, { slots }) =>
|
|
50
|
+
h(LinkExternal, { data: value }, slots.default),
|
|
51
|
+
linkInternal: ({ value }, { slots }) =>
|
|
52
|
+
h(LinkInternal, { data: value }, slots.default),
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
</script>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component
|
|
3
|
+
:is="component"
|
|
4
|
+
v-if="data"
|
|
5
|
+
:data="data"
|
|
6
|
+
>
|
|
7
|
+
<slot />
|
|
8
|
+
</component>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
const props = defineProps<{ data: object }>()
|
|
13
|
+
|
|
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)
|
|
20
|
+
</script>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<main v-if="sanityData.modules?.length > 0">
|
|
3
|
+
<SanityComponent
|
|
4
|
+
v-for="module in sanityData.modules"
|
|
5
|
+
:key="module._key"
|
|
6
|
+
:data="module"
|
|
7
|
+
/>
|
|
8
|
+
</main>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
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'
|
|
16
|
+
|
|
17
|
+
const { baseURL } = useRuntimeConfig().public
|
|
18
|
+
|
|
19
|
+
const path = useRoute().fullPath
|
|
20
|
+
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 }`)
|
|
22
|
+
|
|
23
|
+
const seo = computed(() => sanityData.value?.seo)
|
|
24
|
+
const url = computed(() => baseURL + (sanityData.value?.slug || '/'))
|
|
25
|
+
|
|
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)
|
|
28
|
+
|
|
29
|
+
useHead({
|
|
30
|
+
meta: [
|
|
31
|
+
{ name: 'site_name', content: () => globalSEO.value?.site_name },
|
|
32
|
+
{ name: 'og:image', content: () => image.value?.url },
|
|
33
|
+
{ name: 'og:image:width', content: () => image.value?.metadata.dimensions.width },
|
|
34
|
+
{ name: 'og:image:height', content: () => image.value?.metadata.dimensions.height },
|
|
35
|
+
{ name: 'twitter:image', content: () => image.value?.url },
|
|
36
|
+
{ name: 'twitter:image:width', content: () => image.value?.metadata.dimensions.width },
|
|
37
|
+
{ name: 'twitter:image:height', content: () => image.value?.metadata.dimensions.height },
|
|
38
|
+
{ name: 'og:url', content: () => url.value },
|
|
39
|
+
{ name: 'twitter:url', content: () => url.value },
|
|
40
|
+
],
|
|
41
|
+
link: [
|
|
42
|
+
{ rel: 'canonical', href: () => url.value },
|
|
43
|
+
],
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
useSeoMeta({
|
|
47
|
+
robots: () => ((seo.value?.indexable ? '' : 'no') + 'index,follow'),
|
|
48
|
+
title: () => seo.value?.title,
|
|
49
|
+
description: () => seo.value?.description,
|
|
50
|
+
ogTitle: () => seo.value?.opengraph_title,
|
|
51
|
+
ogDescription: () => seo.value?.description,
|
|
52
|
+
twitterTitle: () => seo.value?.opengraph_title,
|
|
53
|
+
twitterDescription: () => seo.value?.description,
|
|
54
|
+
})
|
|
55
|
+
</script>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<NuxtLink
|
|
3
|
+
:to="data.url"
|
|
4
|
+
:options="{ external: true, target: data.newWindow ? '_blank' : null }"
|
|
5
|
+
>
|
|
6
|
+
<slot />
|
|
7
|
+
</NuxtLink>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script setup lang="ts">
|
|
11
|
+
import type { LinkExternal } from '~/types/objects/link/LinkExternal'
|
|
12
|
+
|
|
13
|
+
defineProps<{ data: LinkExternal }>()
|
|
14
|
+
</script>
|
package/dist/types.d.mts
ADDED
package/dist/types.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devite/nuxt-sanity",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Optimizes the configuration for @nuxt/sanity and provides additional helper components.",
|
|
5
|
+
"repository": "devite-io/nuxt-sanity",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Justus Geramb <justus@devite.io>",
|
|
9
|
+
"url": "https://www.devite.io"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/types.d.ts",
|
|
15
|
+
"import": "./dist/module.mjs",
|
|
16
|
+
"require": "./dist/module.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/module.cjs",
|
|
20
|
+
"types": "./dist/types.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@nuxt/kit": "^3.13.2",
|
|
26
|
+
"@nuxtjs/sanity": "^1.12.1",
|
|
27
|
+
"@sanity/types": "^3.57.3"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@nuxt/devtools": "^1.4.2",
|
|
31
|
+
"@nuxt/eslint-config": "^0.5.7",
|
|
32
|
+
"@nuxt/module-builder": "^0.8.4",
|
|
33
|
+
"@nuxt/schema": "^3.13.2",
|
|
34
|
+
"@nuxt/test-utils": "^3.14.2",
|
|
35
|
+
"@portabletext/vue": "^1.0.11",
|
|
36
|
+
"@types/node": "latest",
|
|
37
|
+
"changelogen": "^0.5.5",
|
|
38
|
+
"eslint": "^9.10.0",
|
|
39
|
+
"nuxt": "^3.13.2",
|
|
40
|
+
"typescript": "latest",
|
|
41
|
+
"vitest": "^2.1.1",
|
|
42
|
+
"vue-tsc": "^2.1.6"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dev": "nuxi dev playground",
|
|
46
|
+
"dev:cms": "cd playground/cms && pnpm dev",
|
|
47
|
+
"dev:build": "nuxi build playground",
|
|
48
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
49
|
+
"release": "pnpm lint && pnpm test && pnpm prepack && changelogen --release && pnpm publish --access=public && git push --follow-tags",
|
|
50
|
+
"lint": "eslint .",
|
|
51
|
+
"test": "vitest run --passWithNoTests",
|
|
52
|
+
"test:watch": "vitest watch",
|
|
53
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
54
|
+
}
|
|
55
|
+
}
|