/[sudobot]/trunk/docs/actions/pageinfo.ts
ViewVC logotype

Annotation of /trunk/docs/actions/pageinfo.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 575 - (hide annotations)
Mon Jul 29 17:59:26 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 1123 byte(s)
chore: add trunk
1 rakinar2 575 "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     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26