Documentation Index Fetch the complete documentation index at: https://makeswift-openapi-sync-cosmos-pr-2639.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Arguments
Options for site version and locale. A valid locale string (ex. "en-US").
Controls whether a request for a localized page should fallback to the default locale if the requested locale is not available.
Return type
snapshot
Promise<MakeswiftPageSnapshot | null>
An opaque Snapshot object that is only intended to be rendered by the
<Page> component.
Examples
Basic usage
The following example sets up a catch all route where page snapshots are fetched from Makeswift and rendered using the <Page> component.
src/pages/[[...path]].tsx
import {
GetStaticPathsResult ,
GetStaticPropsContext ,
GetStaticPropsResult ,
} from "next" ;
import {
Page as MakeswiftPage ,
PageProps as MakeswiftPageProps ,
Makeswift ,
type SiteVersion
} from "@makeswift/runtime/next" ;
import { client } from "@/makeswift/client" ;
import "@/makeswift/components" ;
type ParsedUrlQuery = { path ?: string [] };
export async function getStaticPaths () : Promise <
GetStaticPathsResult < ParsedUrlQuery >
> {
const pages = await client . getPages (). toArray ();
return {
paths: pages . map (( page ) => ({
params: {
path: page . path . split ( "/" ). filter (( segment ) => segment !== "" ),
},
})),
fallback: "blocking" ,
};
}
export type PageProps = MakeswiftPageProps & {
siteVersion : SiteVersion | null ;
};
export async function getStaticProps ({
params ,
previewData ,
} : GetStaticPropsContext < ParsedUrlQuery >) : Promise <
GetStaticPropsResult < PageProps >
> {
const path = "/" + ( params ?. path ?? []). join ( "/" );
const siteVersion = Makeswift . getSiteVersion ( previewData );
const snapshot = await client . getPageSnapshot ( path , {
siteVersion ,
});
if ( snapshot == null ) return { notFound: true };
return {
props: {
snapshot ,
siteVersion ,
},
};
}
export default function Page ({ snapshot } : MakeswiftPageProps ) {
return < MakeswiftPage snapshot = { snapshot } /> ;
}
Localization
The following example uses the locale param in getStaticProps to fetch a localized snapshot of a page.
src/pages/[[...path]].tsx
import {
GetStaticPathsResult ,
GetStaticPropsContext ,
GetStaticPropsResult ,
} from "next" ;
import {
Page as MakeswiftPage ,
PageProps as MakeswiftPageProps ,
Makeswift ,
type SiteVersion
} from "@makeswift/runtime/next" ;
import { client } from "@/makeswift/client" ;
import "@/makeswift/components" ;
type ParsedUrlQuery = { path ?: string [] };
export async function getStaticPaths () : Promise <
GetStaticPathsResult < ParsedUrlQuery >
> {
const pages = await client . getPages (). toArray ();
return {
paths: pages . map (( page ) => ({
params: {
path: page . path . split ( "/" ). filter (( segment ) => segment !== "" ),
},
})),
fallback: "blocking" ,
};
}
export type PageProps = MakeswiftPageProps & {
siteVersion : SiteVersion | null ;
locale : string | undefined ;
};
export async function getStaticProps ({
params ,
previewData ,
locale ,
} : GetStaticPropsContext < ParsedUrlQuery >) : Promise <
GetStaticPropsResult < PageProps >
> {
const path = "/" + ( params ?. path ?? []). join ( "/" );
const siteVersion = Makeswift . getSiteVersion ( previewData );
const snapshot = await client . getPageSnapshot ( path , {
siteVersion ,
locale ,
});
if ( snapshot == null ) return { notFound: true };
return {
props: {
snapshot ,
siteVersion ,
locale ,
},
};
}
export default function Page ({ snapshot } : MakeswiftPageProps ) {
return < MakeswiftPage snapshot = { snapshot } /> ;
}
Changelog
Version Changes v0.24.0Adds allowLocaleFallback option v0.11.0Adds locale option v0.2.0getPageSnapshot method introduced