Hello,
My project is a nuxt 3 SSR website with typescript. Vue files use composition API. I'm trying to fill seo meta with prismic fields data meta_title
and meta_description
but event if payload is puplated, SEO are still undefined.
Here's my code (example with my homepage and simplified) :
const prismic = usePrismic()
import { useSeo } from '@/composables/useSeo';
const { data: home, error} = useAsyncData(
'home',
async () => {
const response = prismic.client.getSingle<HomepageDocument>('homepage', {lang: 'fr-fr'})
// some other stuff and queries...
return {
data: response.data,
}
}
);
const metaTitle: ComputedRef<string> = computed<string>(() => !isFilled.keyText(home.value?.data.meta_title) ? `${home.value?.data.meta_title}` : `Some default title`);
const metaDescription: ComputedRef<string | undefined> = computed<string |undefined>(() => `${home.value?.data.meta_description}`);
useSeo({
title: metaTitle.value,
description: metaDescription.value,
image: null,
imageAlt: null
});
useSeo is a composable in typescript :
import type {RuntimeConfig} from "@nuxt/schema";
export interface IItem {
title: string,
description?: string,
image?: any,
imageAlt?: string | null
}
export const useSeo = (item: IItem): void => {
const { t, locale } = useI18n();
const url: URL = useRequestURL()
const config: RuntimeConfig = useRuntimeConfig();
const facebookAppId: string = config.public.facebookAppId as string;
const titleName: string = t('layout.title')
useSeoMeta({
fbAppId: facebookAppId,
title: (): string => item.title,
description: item.description,
ogUrl: (): string => `${url}`,
ogType: 'website',
ogTitle: (): string => `${item.title} | ${titleName}`,
ogDescription: () => item.title,
ogImage: item.image ?? defaultImg,
ogImageAlt: (): string => item.imageAlt ?? '',
ogLocale: (): string => locale.value,
ogSiteName: (): string => titleName,
twitterCard: 'summary_large_image',
twitterSite: (): string => titleName,
twitterTitle: (): string => `${item.title} | ${titleName}`,
twitterDescription: (): string => (undefined !== item.description) ? item.description : '',
twitterImage: item.image ?? defaultImg,
twitterImageAlt: () => item.imageAlt
)
})
Anchor title and description as marked as "undefined" and window social media share are empty. I made sure i'm using SSR and NOT CSR. I've try to replace useAsyncData
with useLazyAsyncData
or change useSeoMeta
by useServerSeoMeta
but without result. In Prismic back-office, fields meta*
are typed as prismic.KeyTextField
.
Hosting provider
Project hosted on netlify.
I've looked at SEO documentation for next in prismic documentation, but nothing for nuxt :( .
Thank you for answers