@@ -3,26 +3,8 @@ import path from "path";
3
3
import Link from "next/link" ;
4
4
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter" ;
5
5
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism" ;
6
+ import { getHooks } from "@/lib/get-hooks" ;
6
7
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
26
8
async function getHookSource ( name : string ) : Promise < string > {
27
9
const hookPath = path . join (
28
10
process . cwd ( ) ,
@@ -36,9 +18,31 @@ async function getHookSource(name: string): Promise<string> {
36
18
}
37
19
}
38
20
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
+
40
43
export async function generateStaticParams ( ) {
41
44
const hooks = await getHooks ( ) ;
45
+
42
46
return hooks . map ( ( hook ) => ( {
43
47
name : hook . name ,
44
48
} ) ) ;
0 commit comments