Skip to content

Commit d4f04ea

Browse files
committed
feat: add metadata form page doc & generate static params
1 parent 18d3d8d commit d4f04ea

File tree

13 files changed

+63
-315
lines changed

13 files changed

+63
-315
lines changed

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

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,58 @@
11
import React from "react";
2+
import type { Metadata } from "next";
23
import Link from "next/link";
34
import { notFound } from "next/navigation";
45
import { ArrowRightIcon, ChevronRightIcon, SearchIcon } from "lucide-react";
56
import { Mdx } from "@/components/mdx/mdx-remote";
67
import { Input } from "@/components/ui/input";
78
import { cn } from "@/utils/classes";
8-
import { type Item, getDocFromSlug } from "@/lib/docs";
9+
import { type Item, getDocFromSlug, getAllDocs } from "@/lib/docs";
910

1011
interface PageProps {
1112
params: {
1213
slug: string[];
1314
};
1415
}
1516

17+
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
18+
const doc = getDocFromSlug(params.slug);
19+
20+
if (!doc) {
21+
return {};
22+
}
23+
24+
return {
25+
title: doc.metadata.title,
26+
description: doc.metadata.description,
27+
// openGraph: {
28+
// title: doc.title,
29+
// description: doc.description,
30+
// type: "article",
31+
// url: absoluteUrl(doc.slug),
32+
// images: [
33+
// {
34+
// url: siteConfig.ogImage,
35+
// width: 1200,
36+
// height: 630,
37+
// alt: siteConfig.name,
38+
// },
39+
// ],
40+
// },
41+
// twitter: {
42+
// card: "summary_large_image",
43+
// title: doc.title,
44+
// description: doc.description,
45+
// images: [siteConfig.ogImage],
46+
// creator: "@shadcn",
47+
// },
48+
};
49+
}
50+
export async function generateStaticParams(): Promise<PageProps["params"][]> {
51+
const allDocs = getAllDocs();
52+
53+
return allDocs.map((doc) => ({ slug: doc.href.split("/").slice(1) }));
54+
}
55+
1656
export default async function Page({ params }: PageProps) {
1757
const doc = getDocFromSlug(params.slug);
1858

src/app/old/components/layout.tsx

-3
This file was deleted.

src/app/old/components/page.tsx

-65
This file was deleted.

src/app/old/hooks/layout.tsx

-3
This file was deleted.

src/app/old/hooks/page.tsx

-42
This file was deleted.

src/app/old/icons/layout.tsx

-3
This file was deleted.

src/app/old/icons/page.tsx

-58
This file was deleted.

src/app/old/pages/layout.tsx

-3
This file was deleted.

src/app/old/pages/page.tsx

-66
This file was deleted.

src/app/old/templates/layout.tsx

-3
This file was deleted.

src/app/old/templates/page.tsx

-65
This file was deleted.

src/lib/docs.ts

+15
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,18 @@ export const getDocFromSlug = (slug: string[]): Doc | null => {
147147

148148
return null;
149149
};
150+
151+
export const getAllDocs = () => {
152+
const directoryPath = path.join(process.cwd(), "content");
153+
return getAllMdxFiles(directoryPath, directoryPath, [], true).map(
154+
({ fullPath, relativePath }) => {
155+
const itemRawContent = fs.readFileSync(fullPath, "utf-8");
156+
const { frontmatter: itemFrontmatter } =
157+
parseMDXFile<DocFrontmatter>(itemRawContent);
158+
return {
159+
...itemFrontmatter,
160+
href: `/${relativePath.join("/").replace("/index", "")}`,
161+
};
162+
}
163+
);
164+
};

0 commit comments

Comments
 (0)