Skip to content

Commit cb5dd3d

Browse files
authored
Merge pull request #33 from Space-DF/feat/get-latest-version-spacedf-docs
feat: get latest version spacedf docs
2 parents 40c6c33 + 18f2499 commit cb5dd3d

3 files changed

Lines changed: 59 additions & 7 deletions

File tree

src/app/_components/VersionLabel.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use client"
22

3-
export default function VersionLabel() {
3+
export default function VersionLabel({ latestVersion }) {
44
const handleClick = () => {
5-
window.location.href = "/blog/v2026.02.13"
5+
window.location.href = `/blog/${latestVersion?.version}`
66
}
77

88
return (
@@ -20,7 +20,7 @@ export default function VersionLabel() {
2020
}}
2121
title="View release notes"
2222
>
23-
v2026.02.13
23+
{latestVersion?.version}
2424
</span>
2525
)
2626
}

src/app/layout.jsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Banner, Head } from "nextra/components"
44
import { getPageMap } from "nextra/page-map"
55
import VersionLabel from "./_components/VersionLabel"
66
import ImageZoomProvider from "../components/ImageZoomProvider"
7+
import { getLatestVersion } from "@/lib/version";
78
import "nextra-theme-docs/style.css"
89
import "./globals.css"
910

@@ -33,6 +34,12 @@ export const metadata = {
3334
}
3435

3536
export default async function RootLayout({ children }) {
37+
38+
const [pageMap, latestVersion] = await Promise.all([
39+
getPageMap(),
40+
getLatestVersion(),
41+
]);
42+
3643
const navbar = (
3744
<Navbar
3845
logo={
@@ -46,15 +53,15 @@ export default async function RootLayout({ children }) {
4653
}}
4754
className="spacedf-logo"
4855
/>
49-
<VersionLabel />
56+
<VersionLabel latestVersion={latestVersion} />
5057
</div>
5158
}
5259
// SpaceDF discord server
5360
chatLink="https://discord.gg/HxCTyMCzuK"
5461
projectLink="https://github.com/Space-DF/spacedf-docs"
5562
/>
5663
)
57-
const pageMap = await getPageMap()
64+
5865
return (
5966
<html lang="en" dir="ltr" suppressHydrationWarning>
6067
<Head
@@ -73,9 +80,9 @@ export default async function RootLayout({ children }) {
7380
<Layout
7481
banner={
7582
<Banner storageKey="SpaceDF Launch">
76-
🚀 SpaceDF v2026.02.13 is now live!{" "}
83+
🚀 SpaceDF {latestVersion?.version} is now live!{" "}
7784
<a
78-
href="/blog/v2026.02.13"
85+
href={`/blog/${latestVersion?.version}`}
7986
style={{ color: "inherit", textDecoration: "underline" }}
8087
>
8188
Read the release notes

src/lib/version.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import fs from "fs"
2+
import path from "path"
3+
import matter from "gray-matter"
4+
5+
type LatestVersion = {
6+
slug: string
7+
version: string
8+
date?: string
9+
title?: string
10+
type?: string
11+
author?: string
12+
description?: string
13+
}
14+
15+
export const getLatestVersion = async (): Promise<LatestVersion | null> => {
16+
const POSTS_DIR = path.join(process.cwd(), "src/app/blog/(post)")
17+
18+
if (!fs.existsSync(POSTS_DIR)) return null
19+
20+
const results: LatestVersion[] = []
21+
const folders = fs.readdirSync(POSTS_DIR)
22+
23+
for (const folder of folders) {
24+
const fullPath = path.join(POSTS_DIR, folder, "page.mdx")
25+
if (!fs.existsSync(fullPath)) continue
26+
27+
const raw = fs.readFileSync(fullPath, "utf-8")
28+
if (!raw) continue
29+
30+
const { data } = matter(raw)
31+
32+
results.push({
33+
...(data as Omit<LatestVersion, "slug" | "version">),
34+
version: folder,
35+
slug: `/blog/${folder}`,
36+
})
37+
}
38+
39+
const latest =
40+
results.sort(
41+
(a, b) => new Date(b.date ?? 0).getTime() - new Date(a.date ?? 0).getTime(),
42+
)[0] ?? null
43+
44+
return latest
45+
}

0 commit comments

Comments
 (0)