File tree Expand file tree Collapse file tree 3 files changed +11
-35
lines changed Expand file tree Collapse file tree 3 files changed +11
-35
lines changed Original file line number Diff line number Diff line change 11import React from "react" ;
22import 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-
284export 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 ) ;
Original file line number Diff line number Diff 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 >
Original file line number Diff line number Diff line change 11import { MetadataRoute } from "next" ;
22import { groq } from "next-sanity" ;
3- import { sanityFetch } from "@/sanity/lib/live " ;
3+ import { client } from "@/sanity/lib/client " ;
44
55const POSTS_PER_SITEMAP = 50000 ;
66
77export 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}
You can’t perform that action at this time.
0 commit comments