Next.js Starter Kit
Words are nice... but code speaks louder. Dive into a fully commented project template, showcasing these techniques (and more) in action.
Sorry, no results found for "".
Similarly to what we offer with responsive images, our GraphQL API also offers a way to fetch pre-computed SEO meta tags based on the content you insert inside DatoCMS.
You can easily use this information inside your Next app with the help of our react-datocms
package.
Here's a sample of the meta tags you can automatically generate:
To use this feature, install the react-datocms
package:
npm install react-datocms
Then, inside your page, feed content coming from a faviconMetaTags
or _seoMetaTags
query directly into the toNextMetadata
function:
import { toNextMetadata } from "react-datocms";import { performRequest } from 'lib/datocms';
import Head from "next/head";
const PAGE_CONTENT_QUERY = `{ site: _site { favicon: faviconMetaTags { attributes content tag } } blog { seo: _seoMetaTags { attributes content tag } title }}`;
function fetchContent() { return performRequest(PAGE_CONTENT_QUERY, { variables: { limit: 10 } });}
export async function generateMetadata() { const { site, blog } = await fetchContent();
return toNextMetadata([ ...site.favicon, ..blog.seo ])}
export default function Home() { const { blog } = await fetchContent();
// [...]}
Want to know more about SEO customization in DatoCMS? Check out this video tutorial: