@@ -5,7 +5,7 @@ import { getSecret } from "astro:env/server"
55import { searchClient } from " @algolia/client-search"
66import { ChangelogItem } from " ~/components/ChangelogSnippet/types"
77import ChangelogCard from " ~/components/ChangelogSnippet/ChangelogCard.astro"
8- import { SvgArrowLeft , SvgArrowLeft2 , SvgTaillessArrowLeftSmall , Typography } from " @chainlink/blocks"
8+ import { SvgArrowLeft2 , Typography } from " @chainlink/blocks"
99
1010export async function getStaticPaths() {
1111 const appId = getSecret (" ALGOLIA_APP_ID" )
@@ -20,22 +20,41 @@ export async function getStaticPaths() {
2020 const client = searchClient (appId , apiKey )
2121
2222 try {
23- // Fetch all changelog items from Algolia
24- const req = await client .search ({
25- requests: [
26- {
27- indexName: " Changelog" ,
28- hitsPerPage: 1000 , // Adjust based on expected total number of changelog items
29- },
30- ],
31- })
32-
33- console .log (req )
34- const firstResult = req .results [0 ]
35- const logs = " hits" in firstResult ? (firstResult .hits as ChangelogItem []) : []
23+ const records: ChangelogItem [] = []
24+ let currentPage = 0
25+ let nbPages = 1
26+ const hitsPerPage = 1000 // Maximum allowed by Algolia
27+
28+ // Fetch all changelog items from Algolia with pagination
29+ while (currentPage < nbPages ) {
30+ const req = await client .search ({
31+ requests: [
32+ {
33+ indexName: " Changelog" ,
34+ hitsPerPage ,
35+ page: currentPage ,
36+ },
37+ ],
38+ })
39+
40+ const firstResult = req .results [0 ]
41+
42+ if (" hits" in firstResult ) {
43+ // Add hits from current page to records
44+ const hits = firstResult .hits as ChangelogItem []
45+ records .push (... hits )
46+
47+ // Update nbPages from the response
48+ if (" nbPages" in firstResult ) {
49+ nbPages = firstResult .nbPages as number
50+ }
51+ }
52+
53+ currentPage ++
54+ }
3655
3756 // Generate static paths for each changelog item
38- return logs .map ((log ) => ({
57+ return records .map ((log ) => ({
3958 params: { id: log .slug },
4059 props: { log },
4160 }))
0 commit comments