Next.js supports exporting a metadata object from your MDX files, which can be used to enhance SEO and social sharing features. This is especially useful for blog posts and documentation pages.
You can export a metadata object at the top of your MDX file like this:
export const metadata = {
title: 'How to Export Metadata from MDX for Next.js SEO',
description: 'A guide on exporting metadata from MDX files to leverage Next.js SEO features.',
authors: [{ name: 'Jane Doe', url: 'https://janedoe.com' }],
openGraph: {
images: [
'https://cdn.cosmos.so/example-image.jpg',
],
},
}
This metadata will be picked up by Next.js and can be used for SEO, Open Graph, and other meta tags.
This post demonstrates how to export metadata from MDX files for use with Next.js SEO features, inspired by leerob's site.