For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign in
DocsAPI ReferenceChangelog
DocsAPI ReferenceChangelog
  • Get started
    • Quickstart
    • Concepts
  • Guides
    • Environments
  • Reference
      • Makeswift API Handler
        • getSitemap
    • Product docs
    • Blog
    • Support
Sign in
LogoLogo
On this page
  • Options
  • Return type
  • Examples
  • Using next-sitemap
  • Filtering by pathname
  • Using pagination
  • Localization
  • Changelog
Reference@makeswift/runtimeLegacy APIs

getSitemap

Was this page helpful?
Previous

getSiteVersion

Built with

An instance method that provides SEO information about the pages created within Makeswift. You can combine the results of getSitemap with SEO information for your hardcoded pages to create a sitemap.

This method was deprecated in v0.19.0 and was removed in v0.25.0. Use the getPages method to create a sitemap instead, see the documentation here.

A sitemap is a structured list of pages that enables web crawlers to find the pages of a site.

Options

limit
numberDefaults to 50

Number of sitemap entries to fetch.

after
string

Starting id cursor of the last sitemap entry fetched.

pathnamePrefix
stringDefaults to /

Only sitemap entries beginning with this pathname will be returned.

locale
string

A valid locale string (ex. "en-US").

Return type

1type Sitemap = {
2 id: string;
3 loc: string;
4 lastmod?: string;
5 changefreq?:
6 | "always"
7 | "hourly"
8 | "daily"
9 | "weekly"
10 | "monthly"
11 | "yearly"
12 | "never";
13 priority?: number;
14 alternateRefs?: {
15 hreflang: string;
16 href: string;
17 }[];
18}[];

Examples

Using next-sitemap

The following example uses getSitemap with next-sitemap, a popular Next.js library for generating sitemaps.

pages/sitemap.xml.ts
1import { Makeswift } from "@makeswift/runtime/next";
2// Use `getServerSideSitemapLegacy` for sitemap entries in the pages directory.
3import { getServerSideSitemapLegacy } from "next-sitemap";
4
5import { client } from "makeswift/client";
6import { runtime } from "makeswift/runtime";
7import "makeswift/components";
8
9export async function getServerSideProps(context) {
10 const sitemap = await client.getSitemap();
11
12 return getServerSideSitemapLegacy(context, sitemap);
13}
14
15export default function Sitemap() {}

Filtering by pathname

The following example uses the pathnamePrefix option to filter results to only include pages with a pathname beginning with /blog/.

pages/sitemap.xml.ts
1import { Makeswift } from "@makeswift/runtime/next";
2import { getServerSideSitemapLegacy } from "next-sitemap";
3
4import { client } from "makeswift/client";
5import { runtime } from "makeswift/runtime";
6import "makeswift/components";
7
8export async function getServerSideProps(context) {
9 const blogSitemap = await client.getSitemap({ pathnamePrefix: "/blog/" });
10
11 return getServerSideSitemapLegacy(context, blogSitemap);
12}
13
14export default function BlogSitemap() {}

Using pagination

The following example uses the limit and after field to paginate the results of getSitemap 10 entries at a time.

pages/sitemap.xml.ts
1import { Makeswift, Sitemap } from "@makeswift/runtime/next";
2import { getServerSideSitemapLegacy } from "next-sitemap";
3
4import { client } from "makeswift/client";
5import { runtime } from "makeswift/runtime";
6import "makeswift/components";
7
8export async function getServerSideProps(context) {
9 const sitemap: Sitemap = [];
10 let page: Sitemap = [];
11 let after: string | undefined = undefined;
12
13 do {
14 page = await client.getSitemap({ limit: 10, after });
15
16 sitemap.push(...page);
17 after = page.at(-1)?.id;
18 } while (page.length > 0);
19
20 return getServerSideSitemapLegacy(context, sitemap);
21}
22
23export default function Sitemap() {}

Localization

The following example uses the locale option to fetch the sitemap for a specific locale.

pages/sitemap.xml.ts
1import { Makeswift } from "@makeswift/runtime/next";
2import { getServerSideSitemapLegacy } from "next-sitemap";
3
4import { client } from "makeswift/client";
5import { runtime } from "makeswift/runtime";
6import "makeswift/components";
7
8export async function getServerSideProps(context) {
9 const sitemap = await client.getSitemap({ locale: "es" });
10
11 return getServerSideSitemapLegacy(context, sitemap);
12}
13
14export default function Sitemap() {}

If a locale is using domain-based localization, passing the locale to getSitemap will return the sitemap for that particular domain.

For example, if in the site settings there is an es locale with a domain of foo.es, then passing es to getSitemap will return the sitemap for foo.es.

Changelog

VersionChanges
v0.11.2Added locale option to getSitemap
v0.10.7Released getSitemap