Skip to content

Commit 0de17bd

Browse files
committed
fix: add sitemap
1 parent 5cde952 commit 0de17bd

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed

apps/www/app/docs/@details/[name]/page.tsx

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,8 @@ import path from "path";
33
import Link from "next/link";
44
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
55
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism";
6+
import { getHooks } from "@/lib/get-hooks";
67

7-
// Define the hook metadata type
8-
type HookMeta = {
9-
name: string;
10-
description: string;
11-
category: string;
12-
examples?: Array<{ name: string; description: string }>;
13-
};
14-
15-
// Function to get all hooks metadata
16-
async function getHooks(): Promise<HookMeta[]> {
17-
const hooksPath = path.join(
18-
process.cwd(),
19-
"../../packages/hooks/src/index.json"
20-
);
21-
const data = await fs.readFile(hooksPath, "utf8");
22-
return JSON.parse(data);
23-
}
24-
25-
// Function to get a specific hook's source code
268
async function getHookSource(name: string): Promise<string> {
279
const hookPath = path.join(
2810
process.cwd(),
@@ -36,9 +18,31 @@ async function getHookSource(name: string): Promise<string> {
3618
}
3719
}
3820

39-
// Generate static params for all hooks
21+
export async function generateMetadata({
22+
params,
23+
}: {
24+
params: Promise<{ name: string }>;
25+
}) {
26+
const { name } = await params;
27+
const hooks = await getHooks();
28+
const hook = hooks.find((h) => h.name === name);
29+
30+
if (!hook) {
31+
return {
32+
title: "Hook not found",
33+
description: "The requested hook could not be found",
34+
};
35+
}
36+
37+
return {
38+
title: hook.name,
39+
description: hook.description,
40+
};
41+
}
42+
4043
export async function generateStaticParams() {
4144
const hooks = await getHooks();
45+
4246
return hooks.map((hook) => ({
4347
name: hook.name,
4448
}));

apps/www/app/sitemap.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { MetadataRoute } from "next";
2+
import { getHooks } from "@/lib/get-hooks";
3+
4+
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
5+
const hooks = await getHooks();
6+
7+
const staticPages: MetadataRoute.Sitemap = [
8+
{
9+
url: "https://usehooks.io",
10+
lastModified: new Date(),
11+
changeFrequency: "yearly",
12+
priority: 1,
13+
},
14+
{
15+
url: "https://usehooks.io/docs",
16+
lastModified: new Date(),
17+
changeFrequency: "monthly",
18+
priority: 0.8,
19+
},
20+
];
21+
22+
const hookPages: MetadataRoute.Sitemap = hooks.map((hook) => ({
23+
url: `https://usehooks.io/docs/${hook.name}`,
24+
lastModified: new Date(),
25+
changeFrequency: "weekly",
26+
priority: 0.6,
27+
}));
28+
29+
return [...staticPages, ...hookPages];
30+
}

apps/www/lib/get-hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type HookMeta = {
44
name: string;
55
description: string;
66
category: string;
7+
examples: [{ name: string; description: string }];
78
};
89

910
const hooksUrl =

0 commit comments

Comments
 (0)