Skip to content

Instantly share code, notes, and snippets.

@ekrist1
Created April 22, 2023 14:54
Show Gist options
  • Save ekrist1/4811b07eefd3c0152aab6aec55db5950 to your computer and use it in GitHub Desktop.
Save ekrist1/4811b07eefd3c0152aab6aec55db5950 to your computer and use it in GitHub Desktop.
Sanity serializers to convert a tag to nuxt-link (nuxt 3).
//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