Skip to content

Commit 24052f9

Browse files
fix(web): server side fetch sponsor on docs page
1 parent 0a2982a commit 24052f9

File tree

6 files changed

+28
-62
lines changed

6 files changed

+28
-62
lines changed

apps/web/next.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createMDX } from "fumadocs-mdx/next";
2-
import type { NextConfig } from 'next'
3-
2+
import type { NextConfig } from "next";
43

54
const withMDX = createMDX();
65

@@ -30,4 +29,4 @@ const config: NextConfig = {
3029
},
3130
};
3231

33-
export default withMDX(config);
32+
export default withMDX(config);

apps/web/source.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const docs = defineDocs({
66
postprocess: {
77
includeProcessedMarkdown: true,
88
},
9-
}
9+
},
1010
});
1111

1212
export default defineConfig({
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { getLLMText } from '@/lib/get-llm-text';
2-
import { source } from '@/lib/source';
3-
import { notFound } from 'next/navigation';
1+
import { notFound } from "next/navigation";
2+
import { getLLMText } from "@/lib/get-llm-text";
3+
import { source } from "@/lib/source";
44

55
export const revalidate = false;
66

77
export async function GET(
8-
_req: Request,
9-
{ params }: RouteContext<'/llms.mdx/[[...slug]]'>,
8+
_req: Request,
9+
{ params }: RouteContext<"/llms.mdx/[[...slug]]">,
1010
) {
11-
const { slug } = await params;
12-
const page = source.getPage(slug);
13-
if (!page) notFound();
11+
const { slug } = await params;
12+
const page = source.getPage(slug);
13+
if (!page) notFound();
1414

15-
return new Response(await getLLMText(page), {
16-
headers: {
17-
'Content-Type': 'text/markdown',
18-
},
19-
});
15+
return new Response(await getLLMText(page), {
16+
headers: {
17+
"Content-Type": "text/markdown",
18+
},
19+
});
2020
}
2121

2222
export function generateStaticParams() {
23-
return source.generateParams();
24-
}
23+
return source.generateParams();
24+
}

apps/web/src/components/special-sponsor-banner.tsx

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"use client";
21
import { Github, Globe, Star } from "lucide-react";
32
import Image from "next/image";
4-
import { useEffect, useState } from "react";
53
import {
64
HoverCard,
75
HoverCardContent,
@@ -12,42 +10,11 @@ import {
1210
getSponsorUrl,
1311
sortSpecialSponsors,
1412
} from "@/lib/sponsor-utils";
15-
import type { Sponsor, SponsorsData } from "@/lib/types";
13+
import { fetchSponsors } from "@/lib/sponsors";
1614

17-
export function SpecialSponsorBanner() {
18-
const [specialSponsors, setSpecialSponsors] = useState<Sponsor[]>([]);
19-
const [loading, setLoading] = useState(true);
20-
21-
useEffect(() => {
22-
fetch("https://sponsors.better-t-stack.dev/sponsors.json")
23-
.then((res) => {
24-
if (!res.ok) throw new Error("Failed to fetch sponsors");
25-
return res.json();
26-
})
27-
.then((data: SponsorsData) => {
28-
const specials = sortSpecialSponsors(data.specialSponsors);
29-
setSpecialSponsors(specials);
30-
setLoading(false);
31-
})
32-
.catch(() => {
33-
setLoading(false);
34-
});
35-
}, []);
36-
37-
if (loading) {
38-
return (
39-
<div>
40-
<div className="grid grid-cols-4 items-center gap-2 py-1">
41-
{["s1", "s2", "s3", "s4"].map((key) => (
42-
<div
43-
key={key}
44-
className="size-12 animate-pulse rounded border border-border bg-muted"
45-
/>
46-
))}
47-
</div>
48-
</div>
49-
);
50-
}
15+
export async function SpecialSponsorBanner() {
16+
const data = await fetchSponsors();
17+
const specialSponsors = sortSpecialSponsors(data.specialSponsors);
5118

5219
if (!specialSponsors.length) {
5320
return null;

apps/web/src/lib/get-llm-text.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { source } from '@/lib/source';
2-
import type { InferPageType } from 'fumadocs-core/source';
1+
import type { InferPageType } from "fumadocs-core/source";
2+
import type { source } from "@/lib/source";
33

44
export async function getLLMText(page: InferPageType<typeof source>) {
5-
const processed = await page.data.getText('processed');
5+
const processed = await page.data.getText("processed");
66

7-
return `# ${page.data.title} (${page.url})
7+
return `# ${page.data.title} (${page.url})
88
99
${processed}`;
10-
}
10+
}

apps/web/src/lib/sponsors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { SponsorsData } from "./types";
22

33
const SPONSORS_URL = "https://sponsors.better-t-stack.dev/sponsors.json";
44

5-
export async function fetchSponsors(): Promise<SponsorsData> {
5+
export async function fetchSponsors() {
66
try {
77
const response = await fetch(SPONSORS_URL, {
88
next: { revalidate: 3600 },

0 commit comments

Comments
 (0)