Skip to content

Instantly share code, notes, and snippets.

@FlxRobole
Last active November 4, 2025 14:56
Show Gist options
  • Select an option

  • Save FlxRobole/a0aa539ecb6c07e34c0711834eb0e4c9 to your computer and use it in GitHub Desktop.

Select an option

Save FlxRobole/a0aa539ecb6c07e34c0711834eb0e4c9 to your computer and use it in GitHub Desktop.
Use @strapi/plugin-seo with nuxt
/**
* Simple `useSeo()` composable to connect API output of @strapi/plugin-seo with Nuxt 4.
*
* Usage example (using Nuxt Strapi - https://strapi.nuxtjs.org/usage#findone):
*
* const { findOne } = useStrapi();
* const response = await findOne<SingleTypePage>('restaurants', 'xyz', {
* populate: ['seo.openGraph.ogImage', 'seo.metaImage']
* });
* useSeo(response.data.seo);
*/
export interface StrapiSEOOpenGraph {
ogDescription?: string;
ogImage?: Media;
ogTitle?: string;
ogType?: string;
ogUrl?: string;
}
export interface StrapiSEO {
canonicalURL?: string;
keywords?: string;
metaDescription?: string;
metaImage?: Media;
metaRobots?: string;
metaTitle?: string;
metaViewport?: string;
openGraph?: StrapiSEOOpenGraph;
structuredData?: any;
}
export const useSeo = (seo: StrapiSEO) => {
const seoMeta = computed(() => {
if (!seo) return;
return {
title: seo.metaTitle,
description: seo.metaDescription,
canonical: seo.canonicalURL,
robots: seo.metaRobots,
viewport: seo.metaViewport,
keywords: seo.keywords,
image: seo.metaImage
? useStrapiMedia(seo.metaImage.url)
: undefined,
...(seo.openGraph
? {
...seo.openGraph,
ogImage: seo.openGraph.ogImage
? useStrapiMedia(seo.openGraph.ogImage.url)
: undefined,
}
: undefined
),
}
});
useSeoMeta(seoMeta.value);
// @todo insert seo.structuredData into <body>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment