Skip to content

Commit 0ae189a

Browse files
committed
refactor: replace latest-version utility with github API integration and add last edit functionality
1 parent db9c21c commit 0ae189a

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

content/docs/worlds/api/repository.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Repository
44

55
import { Tab, Tabs } from "fumadocs-ui/components/tabs"
66
import { DynamicCodeBlock } from "fumadocs-ui/components/dynamic-codeblock"
7-
import { latestVersion } from "@/lib/latest-version"
7+
import { latestVersion } from "@/lib/github"
88
export const version = await latestVersion("worlds")
99

1010
To start, add our repository to your project:
@@ -75,6 +75,6 @@ Add Worlds' API codebase as a dependency:
7575
</Tabs>
7676

7777
<Callout type="info" title="Note">
78-
The version of the Worlds API is the same as the version of the Worlds plugin.
79-
You can find all versions on the [releases page](https://github.com/TheNextLvl-net/worlds/releases).
78+
The version of the Worlds API is the same as the version of the Worlds plugin. You can find all
79+
versions on the [releases page](https://github.com/TheNextLvl-net/worlds/releases).
8080
</Callout>

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { DocsPage, DocsBody, DocsDescription, DocsTitle } from "fumadocs-ui/page
33
import { notFound } from "next/navigation"
44
import { createRelativeLink } from "fumadocs-ui/mdx"
55
import { getMDXComponents } from "@/mdx-components"
6+
import { lastEdit } from "@/lib/github"
7+
import { SiGithub } from "@icons-pack/react-simple-icons"
68

79
export default async function Page(props: { params: Promise<{ slug?: string[] }> }) {
810
const params = await props.params
@@ -15,12 +17,22 @@ export default async function Page(props: { params: Promise<{ slug?: string[] }>
1517
<DocsPage
1618
toc={page.data.toc}
1719
full={page.data.full}
20+
lastUpdate={await lastEdit(page)}
1821
tableOfContent={{
1922
style: "clerk",
2023
}}
2124
>
2225
<DocsTitle>{page.data.title}</DocsTitle>
23-
<DocsDescription>{page.data.description}</DocsDescription>
26+
<DocsDescription className="mb-0">{page.data.description}</DocsDescription>
27+
28+
<a
29+
href={`https://github.com/TheNextLvl-net/docs/blob/main/content/docs/${page.file.path}`}
30+
rel="noreferrer noopener"
31+
target="_blank"
32+
className="mb-8 w-fit border flex items-center gap-2 rounded-md p-2 font-medium text-xs text-fd-secondary-foreground hover:text-fd-accent-foreground hover:bg-fd-accent"
33+
>
34+
<SiGithub className="size-4" /> Edit on GitHub
35+
</a>
2436
<DocsBody>
2537
<MDXContent
2638
components={getMDXComponents({

src/lib/github.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { getGithubLastEdit } from "fumadocs-core/server"
2+
import { Page } from "fumadocs-core/source"
3+
4+
export async function latestVersion(repo: string) {
5+
const response = await fetch(
6+
`https://api.github.com/repos/TheNextLvl-net/${encodeURIComponent(repo)}/releases/latest`,
7+
{
8+
headers: {
9+
...(process.env.GITHUB_TOKEN && {
10+
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
11+
}),
12+
Accept: "application/vnd.github.v3+json",
13+
},
14+
cache: "force-cache",
15+
next: {
16+
revalidate: 3600,
17+
},
18+
},
19+
)
20+
21+
if (!response.ok) {
22+
return "VERSION"
23+
}
24+
25+
const data = await response.json()
26+
return data.tag_name
27+
}
28+
29+
export async function lastEdit(page: Page): Promise<Date> {
30+
var time = await getGithubLastEdit({
31+
owner: "TheNextLvl-net",
32+
repo: "docs",
33+
token: process.env.GITHUB_TOKEN,
34+
path: `content/docs/${page.file.path}`,
35+
}).catch((error) => {
36+
console.error("Error fetching last edit date:", error)
37+
return new Date(0)
38+
})
39+
return time ? time : new Date(0)
40+
}

src/lib/latest-version.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)