Skip to content

Commit f0edfe2

Browse files
CopilotkingRayhan
andauthored
refactor: derive page title from slug automatically, remove PAGE_TITLES map
Agent-Logs-Url: https://github.com/techdiary-dev/techdiary.dev/sessions/1c7cd8e3-a305-4ee3-a503-b3fb88ca3e09 Co-authored-by: kingRayhan <7611746+kingRayhan@users.noreply.github.com>
1 parent 9af3d36 commit f0edfe2

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/app/pages/[slug]/page.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ interface Props {
99
params: Promise<{ slug: string }>;
1010
}
1111

12-
const PAGE_TITLES: Record<string, string> = {
13-
privacy: "Privacy Policy",
14-
"terms-and-conditions": "Terms and Conditions",
15-
};
12+
function slugToTitle(slug: string): string {
13+
return slug
14+
.split("-")
15+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
16+
.join(" ");
17+
}
1618

1719
async function getPageContent(slug: string): Promise<string | null> {
1820
"use cache";
@@ -23,7 +25,7 @@ async function getPageContent(slug: string): Promise<string | null> {
2325

2426
export async function generateMetadata({ params }: Props): Promise<Metadata> {
2527
const { slug } = await params;
26-
const title = PAGE_TITLES[slug] ?? slug;
28+
const title = slugToTitle(slug);
2729
return { title };
2830
}
2931

0 commit comments

Comments
 (0)