Created
April 22, 2023 14:54
-
-
Save ekrist1/4811b07eefd3c0152aab6aec55db5950 to your computer and use it in GitHub Desktop.
Sanity serializers to convert a tag to nuxt-link (nuxt 3).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//helpers/link.vue | |
<template> | |
<nuxt-link :to="href" v-if="isInternalLink"> <slot /></nuxt-link> | |
<a :href="href" v-else> <slot /></a> | |
</template> | |
<script setup> | |
const props = defineProps({ | |
href: String | |
}) | |
const isInternalLink = computed(() => { | |
return props.href.startsWith('/') ? true : false | |
}) | |
</script> | |
//Nuxt page or Nuxt component | |
<template> | |
<SanityContent :blocks="block1.page.body" :serializers="serializers" /> | |
<template/> | |
<script setup> | |
import Link from '~/helpers/Link.vue' | |
const serializers = { | |
types: { | |
youtube: YouTube | |
}, | |
marks: { link: Link }, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment