Skip to content

Commit 9af3d36

Browse files
CopilotkingRayhan
andauthored
refactor: replace per-page routes with a single dynamic /pages/[slug] route
Agent-Logs-Url: https://github.com/techdiary-dev/techdiary.dev/sessions/a855d7fb-9660-4b2e-81eb-1c10ef835fc7 Co-authored-by: kingRayhan <7611746+kingRayhan@users.noreply.github.com>
1 parent f33e632 commit 9af3d36

3 files changed

Lines changed: 47 additions & 68 deletions

File tree

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import BaseLayout from "@/components/layout/BaseLayout";
2+
import Markdown from "@/lib/markdown/Markdown";
3+
import { existsSync, readFileSync } from "fs";
4+
import { join } from "path";
5+
import { Metadata } from "next";
6+
import { notFound } from "next/navigation";
7+
8+
interface Props {
9+
params: Promise<{ slug: string }>;
10+
}
11+
12+
const PAGE_TITLES: Record<string, string> = {
13+
privacy: "Privacy Policy",
14+
"terms-and-conditions": "Terms and Conditions",
15+
};
16+
17+
async function getPageContent(slug: string): Promise<string | null> {
18+
"use cache";
19+
const filePath = join(process.cwd(), "src/content", `${slug}.md`);
20+
if (!existsSync(filePath)) return null;
21+
return readFileSync(filePath, "utf-8");
22+
}
23+
24+
export async function generateMetadata({ params }: Props): Promise<Metadata> {
25+
const { slug } = await params;
26+
const title = PAGE_TITLES[slug] ?? slug;
27+
return { title };
28+
}
29+
30+
const StaticMarkdownPage = async ({ params }: Props) => {
31+
const { slug } = await params;
32+
const content = await getPageContent(slug);
33+
34+
if (!content) notFound();
35+
36+
return (
37+
<BaseLayout>
38+
<div className="max-w-3xl mx-auto my-10 px-4">
39+
<div className="content-typography">
40+
<Markdown content={content} />
41+
</div>
42+
</div>
43+
</BaseLayout>
44+
);
45+
};
46+
47+
export default StaticMarkdownPage;

src/app/pages/privacy/page.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/app/pages/terms-and-conditions/page.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)