Options
Number of pages to fetch. Must be between
1 and 100.Starting
id cursor of the last page entry that was fetched.A filter to only retrieve pages with a pathname that begins with this value.
A valid locale string (ex.
"en-US").The field to sort the result pages by. Can be any one of the following:
'title', 'path', 'description', 'createdAt', 'updatedAt'.The direction of how the result pages are sorted. Can be either
'asc' or 'desc'.Used to either retrieve the published version or working version of Makeswift
pages. Can either be
Live or WorkingWhether the results should include pages that are offline in Makeswift.
Return Type
Concepts
Pagination & Async Iterables
The requests made bygetPages are paginated. A paginated request will only
retrieve a portion of the total pages per request. If you have a large number of
pages, you may need to paginate through the results to retrieve all of them.
To make this easier, the returned value of getPages is an extension of a
Promise and an AsyncIterable. This abstraction enables you to consume the
pages in multiple ways, allowing you to easily retrieve all pages without
worrying about the implementation details of pagination:
get-pages.ts
getPages includes the following methods:
-
toArray(): Promise<T[]>: Consumes all pages in the iterable and returns them as an array. -
map(callback: (item: T) => U): Maps over each page in the iterable to yield a new data type. Returns another async iterable. -
filter(predicate: (item: T) => Boolean): Selectively yields pages based on a predicate function. Returns another async iterable.
.map and .filter return another iterable, you can chain these
methods together:
id of a page to the after option to retrieve the next set of pages after
that page. This can be used to manually implement paginating through all pages:
get-pages.ts
Site Versions
By default,getPages will return data reflecting the state of published
Makeswift pages. To specify which variant of your pages you want to retrieve,
you can pass a value to the siteVersion option. If your site is using pages
router, use the getSiteVersion method to
retrieve the current site version. If your site is using app router, use the
getSiteVersion function.
Note that the publishedAt field of a page will always be null when
retrieving non-live versions of the site. This is because the page data has not
been published yet.
Similarly, if you need to retrieve information on pages that are not currently
online (even if they have been published), you can pass includeOffline: true
to the getPages method. By default, offline pages are excluded from results.
Usage
Path Prefix Filtering
Path prefix filtering allows you to selectively retrieve your Makeswift pages based on if they start with a specific path. For example, suppose you have many pages organized under the path/blog/. You can use the pathPrefix option to
retrieve all pages that start with /blog/:
Static Path Generation
Since Makeswift pages use dynamic routes with Next.js, you may want to statically generate paths for your pages at build time. In pages router, this can be done by defininggetStaticPaths
on your catch-all page:
src/pages/[[...path]].tsx
generateStaticParams
on your dynamically routed page:
app/[[...path]]/page.tsx
Generating a Sitemap
The data fromgetPages can be used to generate a sitemap.xml file for your
site, allowing search engines to index your pages.
Here’s an example of how to use getPages with the next-sitemap library to
generate a sitemap:
pages/sitemap.xml.ts
getPages to retrieve pages and map them to the format expected by Next.js:
app/sitemap.ts
-
By default,
getPageswill return pages that are excluded from search. You can filter these pages out while constructing your sitemap based on theexcludedFromSearchproperty. -
getPageswill return the path of the page, which is relative to the root of the site. Depending on whether your host is using path-based or domain-based routing for localization, you may need to prepend the domain or locale to the path. -
If you did not explicitly set a
sitemapPriorityorsitemapFrequencyfor a page in the Makeswift builder, these attributes will benullin the response. You can specify default values for these fields in your sitemap generation logic.
Localization
To retrieve pages that you’ve created in one of your registered locales, you can pass thelocale option to the
getPages method. Each returned page will include any of its localized
alternates in the localizedVariants field.
locale option, pages from your site’s default locale will
be returned. Each page will include any of its localized alternates in the
localizedVariants field.
For an example of how to use getPages with localization to statically generate
paths in Next.js app router, see
here.
Changelog
| Version | Changes |
|---|---|
v0.25.2 | Increases default limit from 20 to 100 |
v0.19.0 | Adds pagination, sorting, path filtering, and new data fields to getPages response. getPages now returns an async iterable with toArray, .map, and filter methods. |
v0.13.0 | getPages can retrieve either live or working pages (live by default) |
v0.9.0 | getPages only returns live pages |
v0.2.0 | Released getPages |