1 |
"use server"; |
2 |
|
3 |
import { branch } from "@/utils/links"; |
4 |
|
5 |
export async function getPageInfo(pathname: string) { |
6 |
"use server"; |
7 |
|
8 |
const githubURL = pathname |
9 |
? `https://api.github.com/repos/onesoft-sudo/sudobot/commits?path=${encodeURIComponent( |
10 |
"docs/app" + (pathname === "/" ? "" : "/(docs)"), |
11 |
)}${encodeURIComponent(pathname)}${ |
12 |
pathname === "/" ? "" : "%2F" |
13 |
}page.mdx&sha=${encodeURIComponent(branch)}` |
14 |
: null; |
15 |
let lastModifiedDate = new Date(); |
16 |
let avatarURL = null; |
17 |
|
18 |
if (githubURL) { |
19 |
try { |
20 |
const response = await fetch(githubURL, { |
21 |
next: { |
22 |
revalidate: 3600, |
23 |
}, |
24 |
}); |
25 |
|
26 |
const json = await response.json(); |
27 |
const timestamp = json?.[0]?.commit?.author?.date; |
28 |
avatarURL = json?.[0]?.author?.avatar_url; |
29 |
|
30 |
if (timestamp) { |
31 |
lastModifiedDate = new Date(timestamp); |
32 |
} |
33 |
} catch (error) { |
34 |
console.error(error); |
35 |
} |
36 |
} |
37 |
|
38 |
return { lastModifiedDate, avatarURL }; |
39 |
} |