The documentation wasn't much help, so I came here. I am trying to add metadata for my blog posts but I cannot figure out how to do that. This is my articles/[slug]/page.tsx code shortened:
'use client';
import { useEffect, useState } from 'react';
import dynamic from 'next/dynamic';
import fetchBlogPosts from '../../../../pages/api/get_content';
import ArticleHeader from '@/app/components/articleHeader';
import { firestore } from '../../../../firestore';
import { collection, addDoc, query, where, getDocs, Timestamp } from 'firebase/firestore';
import 'react-quill/dist/quill.snow.css';
const ReactQuill = dynamic(() => import('react-quill'), { ssr: false });
type BlogPost = {
title: string;
description: string;
image?: string | null;
content: string;
slug: string;
tags: Array<{ name: string }>;
};
const ArticlePage = ({ params, }: { params: { slug: string } }) => {
};
export default ArticlePage;
What do I need to do to have dynamic metadata?
You can use generateMetadata. In my example, I set dynamic metadata for my video detail page:
export const generateMetadata = async ({
params,
searchParams
}: {
params: { id: string };
searchParams: { id: string };
}) => {
const video: Video = await getVideo(params.id);
return {
title: video.title,
description: video.description,
keywords: video.tag
};
};
export default async function Detail(props: any) {
return <div>Video detail page</div>
}