Skip to content

Commit e64bc2b

Browse files
committed
remove GitHub stars fetching from Home component and update SearchClientComponent props
update sitemap generation to use client for fetching
1 parent 383eb3c commit e64bc2b

File tree

3 files changed

+11
-35
lines changed

3 files changed

+11
-35
lines changed

app/(with-support)/page.tsx

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,11 @@
11
import React from "react";
22
import SearchClientComponent from "@/components/SearchClientComponent";
33

4-
interface GitHubRepo {
5-
name: string;
6-
stargazers_count: number;
7-
}
8-
9-
async function fetchGitHubStars(): Promise<Record<string, number>> {
10-
try {
11-
const reposResponse = await fetch(
12-
"https://api.github.com/search/repositories?q=user:apis-guru%20user:Redocly&sort=stars&per_page=10",
13-
{ next: { revalidate: 3600 } }, // Revalidate every hour
14-
);
15-
const reposData = await reposResponse.json();
16-
const githubRepos: GitHubRepo[] = reposData.items || [];
17-
18-
return githubRepos.reduce((acc: Record<string, number>, repo) => {
19-
acc[repo.name] = repo.stargazers_count;
20-
return acc;
21-
}, {});
22-
} catch (error) {
23-
console.error("Failed to fetch GitHub stars:", error);
24-
return {};
25-
}
26-
}
27-
284
export default async function Home() {
29-
const repoStarCounts = await fetchGitHubStars();
30-
315
return (
326
<div className="container mx-auto px-4 py-4 relative">
337
<div className="relative z-10">
34-
<SearchClientComponent repoStarCounts={repoStarCounts} />
8+
<SearchClientComponent />
359
</div>
3610
</div>
3711
);

app/apis/[providerSlug]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default async function ProviderPage({
8484
return (
8585
<div className=" mx-auto px-4 relative">
8686
<SearchClientComponent
87-
repoStarCounts={{}}
87+
8888
providerSlug={providerSlug}
8989
/>
9090
</div>

app/blog/sitemap.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { MetadataRoute } from "next";
22
import { groq } from "next-sanity";
3-
import { sanityFetch } from "@/sanity/lib/live";
3+
import { client } from "@/sanity/lib/client";
44

55
const POSTS_PER_SITEMAP = 50000;
66

77
export async function generateSitemaps() {
88
const countQuery = groq`count(*[_type == "post" && noindex != true])`;
9-
const { data: total } = await sanityFetch({ query: countQuery });
10-
const sitemapsNeeded = Math.ceil((total || 0) / POSTS_PER_SITEMAP);
9+
const total = await client.fetch<number>(countQuery);
10+
const sitemapsNeeded = Math.max(
11+
1,
12+
Math.ceil((total || 0) / POSTS_PER_SITEMAP)
13+
);
1114
return Array.from({ length: sitemapsNeeded }, (_, index) => ({ id: index }));
1215
}
1316

@@ -33,10 +36,9 @@ export default async function sitemap({
3336
}
3437
`;
3538

36-
const { data } = await sanityFetch({
37-
query: postsQuery,
38-
params: { baseUrl },
39+
const posts = await client.fetch<MetadataRoute.Sitemap>(postsQuery, {
40+
baseUrl,
3941
});
4042

41-
return data;
43+
return posts ?? [];
4244
}

0 commit comments

Comments
 (0)