Skip to content

Commit 336de82

Browse files
committed
Implemented static and dynamic metadata generation within (root) route group
1 parent 91643f8 commit 336de82

File tree

11 files changed

+76
-2
lines changed

11 files changed

+76
-2
lines changed

app/(root)/(home)/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import { getQuestions } from "@/lib/actions/question.action";
1515
import { HomePageFilters } from "@/constants/filters";
1616

1717
import type { SearchParamsProps } from "@/types";
18+
import type { Metadata } from "next";
19+
20+
export const metadata: Metadata = {
21+
title: "Home — DevOverflow",
22+
};
1823

1924
export default async function Home({ searchParams }: SearchParamsProps) {
2025
const { userId: clerkId } = auth();

app/(root)/ask-question/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { auth } from "@clerk/nextjs";
33
import Question from "@/components/forms/Question";
44

55
import { getUserById } from "@/lib/actions/user.action";
6+
import type { Metadata } from "next";
7+
8+
export const metadata: Metadata = {
9+
title: "Ask a Question — DevOverflow",
10+
};
611

712
type Props = {};
813

app/(root)/collection/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import { getSavedQuestions } from "@/lib/actions/user.action";
1111
import { QuestionFilters } from "@/constants/filters";
1212

1313
import type { SearchParamsProps } from "@/types";
14+
import type { Metadata } from "next";
15+
16+
export const metadata: Metadata = {
17+
title: "Collection — DevOverflow",
18+
};
1419

1520
export default async function Collection({ searchParams }: SearchParamsProps) {
1621
const { userId: clerkId } = auth();

app/(root)/community/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import { getAllUsers } from "@/lib/actions/user.action";
99
import { UserFilters } from "@/constants/filters";
1010

1111
import type { SearchParamsProps } from "@/types";
12+
import type { Metadata } from "next";
13+
14+
export const metadata: Metadata = {
15+
title: "Community — DevOverflow",
16+
};
1217

1318
const Page = async ({ searchParams }: SearchParamsProps) => {
1419
const result = await getAllUsers({

app/(root)/edit-answer/[id]/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import Answer from "@/components/forms/Answer";
77
import { getAnswerById } from "@/lib/actions/answer.action";
88

99
import type { ParamsProps } from "@/types";
10+
import type { Metadata } from "next";
11+
12+
export const metadata: Metadata = {
13+
title: "Edit Answer — DevOverflow",
14+
};
1015

1116
const Page = async ({ params }: ParamsProps) => {
1217
const { userId } = auth();

app/(root)/profile/[id]/page.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,21 @@ import Stats from "@/components/shared/Stats";
1010
import AnswersTab from "@/components/shared/AnswersTab";
1111
import QuestionsTab from "@/components/shared/QuestionsTab";
1212

13-
import { getUserInfo } from "@/lib/actions/user.action";
13+
import { getUserInfo, getUserById } from "@/lib/actions/user.action";
1414
import { getFormattedJoinedDate } from "@/lib/utils";
1515

1616
import type { URLProps } from "@/types";
17+
import type { Metadata } from "next";
18+
19+
export async function generateMetadata({
20+
params,
21+
}: Omit<URLProps, "searchParams">): Promise<Metadata> {
22+
const user = await getUserById({ userId: params.id });
23+
24+
return {
25+
title: `${user.username}'s Profile — DevOverflow`,
26+
};
27+
}
1728

1829
const Page = async ({ params, searchParams }: URLProps) => {
1930
const { userId: clerkId } = auth();

app/(root)/profile/edit/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import Profile from "@/components/forms/Profile";
55
import { getUserById } from "@/lib/actions/user.action";
66

77
import type { ParamsProps } from "@/types";
8+
import type { Metadata } from "next";
9+
10+
export const metadata: Metadata = {
11+
title: "Edit Profile — DevOverflow",
12+
};
813

914
const Page = async ({ params }: ParamsProps) => {
1015
const { userId } = auth();

app/(root)/question/[id]/page.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ import { getQuestionById } from "@/lib/actions/question.action";
1818
import { getFormattedNumber, getTimestamp } from "@/lib/utils";
1919

2020
import type { URLProps } from "@/types";
21+
import type { Metadata } from "next";
22+
23+
export async function generateMetadata({
24+
params,
25+
}: Omit<URLProps, "searchParams">): Promise<Metadata> {
26+
const question = await getQuestionById({ questionId: params.id });
27+
28+
return {
29+
title: `"${question.title}" — DevOverflow`,
30+
};
31+
}
2132

2233
const Page = async ({ params, searchParams }: URLProps) => {
2334
const { userId: clerkId } = auth();

app/(root)/question/edit/[id]/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { getQuestionById } from "@/lib/actions/question.action";
66
import { getUserById } from "@/lib/actions/user.action";
77

88
import type { ParamsProps } from "@/types";
9+
import type { Metadata } from "next";
10+
11+
export const metadata: Metadata = {
12+
title: "Edit Question — DevOverflow",
13+
};
914

1015
const Page = async ({ params }: ParamsProps) => {
1116
const { userId } = auth();

app/(root)/tags/[id]/page.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@ import NoResult from "@/components/shared/NoResult";
55
import Pagination from "@/components/shared/Pagination";
66
import LocalSearchbar from "@/components/shared/search/LocalSearchbar";
77

8-
import { getQuestionsByTagId } from "@/lib/actions/tag.action";
8+
import { getTagById, getQuestionsByTagId } from "@/lib/actions/tag.action";
99

1010
import type { URLProps } from "@/types";
11+
import type { Metadata } from "next";
12+
13+
export async function generateMetadata({
14+
params,
15+
}: Omit<URLProps, "searchParams">): Promise<Metadata> {
16+
const tag = await getTagById({ tagId: params.id });
17+
18+
return {
19+
title: `Posts by tag '${tag.name}' — DevOverflow`,
20+
description: tag.description || `Questions tagged with ${tag.name}`,
21+
};
22+
}
1123

1224
const Page = async ({ params, searchParams }: URLProps) => {
1325
const { userId: clerkId } = auth();

0 commit comments

Comments
 (0)