Upgrading to 0.19.0

If you haven’t upgraded to 0.18.0 please read the upgrading guide.

This upgrade guide is only necessary if you’re using the getPages Makeswift client method. If you’re not using this method, you can safely skip this upgrade guide.

We also recommend following this guide if you’re using the getSitemap client method, which has been deprecated in this release.

Updating usage of getPages

In previous versions of the runtime, the Makeswift client provided a getPages method to retrieve a list of all Makeswift page paths and their ids in the site.

In v0.19.0, the getPages method now has sorting, path filtering, and pagination. This method was not previously paginated - in order to get all your pages, you may now use our .toArray pagination helper method, which will automatically paginate through all results and aggregate them into an array:

get-all-pages.ts
1import { client } from "../../../../makeswift/client";
2import { MakeswiftPage } from "@makeswift/runtime/next";
3
4async function getAllPages(): Promise<MakeswiftPage[]> {
5 return await client.getPages().toArray();
6}

getPages now returns an instance of IterablePaginationResult, a decorated async iterable which includes methods .map and .filter, in addition to .toArray, mentioned above. The MakeswiftPage type has also been updated to include several more data fields from the Makeswift page.

For more information about the usage of the getPages client method, please refer to the getPages documentation.

Deprecation of getSitemap

v0.19.0 of the runtime also deprecates the getSitemap client method. While getSitemap is still available in this version, it will be removed in a future release. We recommend using the getPages method to construct your sitemap instead.

Note that the deprecation of getSitemap now involves the host being responsible for the construction of page URLs in the sitemap (either with domain or path based localization).

Below is an example for pages router that uses path-based localization with the next-sitemap library:

pages/sitemap.xml.ts
1import { getServerSideSitemapLegacy } from "next-sitemap";
2import { MakeswiftPage } from "@makeswift/runtime/next";
3import { client } from "../../../../makeswift/client";
4
5const DOMAIN = "https://example.com";
6const DEFAULT_PRIORITY = 0.75;
7const DEFAULT_FREQUENCY = "hourly";
8
9function pageToSitemapItem(page: MakeswiftPage) {
10 const pageUrl = new URL(page.path, DOMAIN);
11 return {
12 loc: pageUrl.href,
13 lastmod: page.updatedAt,
14 changefreq: page.sitemapFrequency ?? DEFAULT_FREQUENCY,
15 priority: page.sitemapPriority ?? DEFAULT_PRIORITY,
16 alternateRefs: page.localizedVariants.map((variant) => {
17 const localizedPath = `/${variant.locale}/${variant.path}`;
18 const localizedPageUrl = new URL(localizedPath, DOMAIN);
19 return {
20 hreflang: variant.locale,
21 href: localizedPageUrl.href,
22 };
23 }),
24 };
25}
26
27export async function getServerSideProps(context) {
28 const sitemap = await client
29 .getPages()
30 .filter((page) => !page.excludedFromSearch)
31 .map((page) => pageToSitemapItem(page))
32 .toArray();
33
34 return getServerSideSitemapLegacy(context, sitemap);
35}
36
37export default function Sitemap() {}

Here’s another example for Next.js’s App Router built-in support for sitemaps:

app/sitemap.ts
1import { MetadataRoute } from "next";
2import { MakeswiftPage } from "@makeswift/runtime/dist/types/next";
3import { client } from "../../../../lib/makeswift/client";
4
5type NextSitemapItem = MetadataRoute.Sitemap[number];
6
7const DOMAIN = "https://example.com";
8const DEFAULT_PRIORITY = 0.75;
9const DEFAULT_FREQUENCY = "hourly";
10
11function pageToSitemapEntry(page: MakeswiftPage): NextSitemapItem {
12 const pageUrl = new URL(page.path, DOMAIN);
13 return {
14 url: pageUrl.href,
15 lastModified: page.updatedAt,
16 changeFrequency: page.sitemapFrequency ?? DEFAULT_FREQUENCY,
17 priority: page.sitemapPriority ?? DEFAULT_PRIORITY,
18 };
19}
20
21export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
22 return client
23 .getPages()
24 .filter((page) => !page.excludedFromSearch)
25 .map((page) => pageToSitemapEntry(page))
26 .toArray();
27}

Here is the link to the official release notes.