Retrieve a list of pages (url endpoints)

Using a static site generator (Astro) with builder.io. Seems pretty easy to get a single page. But I want to dynamically create pages. I been looking at the api but I cant seem to find a way to get a list of pages (urls) created in builder.

Seems like this would be simple and I am just likely missing something very easy.

Hi @jeffwllms ! Thanks for the question!

We actually have an example of this very same logic in our Astro starter, which can be found here:

Essentially you would be calling Astro’s getStaticPaths and generate paths based on the URLs entered into you page model entries using the Builder-provided getAllContent method.

Try that out and see if it works for you!

NB, we recently discovered an issue with our Astro starter that causes it to error out sometimes. Our dev team is aware and working to update the code. That being said, the logic around dynamic paths for various models listed above is correct. So, if you have an existing Astro project you should be able to drop this code in there and get it working with little trouble!

Let me know if that works for you, always happy to help trouble shoot if needed !

Thanks @TimG . I did the see sample but noticed it was relying on ‘@builder.io/sdk-solid’ for the getAllContent method.

Anyway, I am not using solidjs just astro SSG and vanillajs. So I think I was searching the content and rest api documentation and didn’t find anything. But I guess there is no reason why I couldn’t use the ‘@builder.io/sdk-solid’ even though I am not using any solidjs components to get these helper functions. Or i can look at he source of the sdk and see what they are doing in that method.

Thanks,

I paid closer attention to what the code is actually doing and figured it out. It is actually just pulling down all content, then using map to just pull out the URLs in a list. Then it does the astro thing and calls each one of the URLs to get the single page.

Seems weird since I already had all the content. Anyway, i am able to do it with plain javascript. Just thought there might be a way to pull down only the URLs in a request and not all the content.

But I think i can make that happen with GraphQL not sure it is any more performant though since the way the data comes down i still need to do a map.

thanks,

Hey @jeffwllms yes you are correct, I was just going to reply something to that effect. You also can reduce the size of the data you are pulling to generate the paths if you use the fields or omit params, like we do here

Hope that helps and let us know how it goes / if you have any further questions!

@TimG yep just figured that out. ‘fields=data.url’ for the win.

So easy. Just wasn’t looking at all the options close enough.

Still need to do the map but not a big deal.

1 Like

Awesome! Let me know how it goes!