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
        • Constructor
        • getPages
        • getPageSnapshot
        • getComponentSnapshot
        • getSiteVersion
      • Makeswift API Handler
    • Product docs
    • Blog
    • Support
Sign in
LogoLogo
On this page
  • Arguments
  • Example
Reference@makeswift/runtimeClient

getSiteVersion

Was this page helpful?
Previous

getComponentSnapshot

Next

MakeswiftApiHandler

Built with

A static method on the Makeswift class that returns the current version of the Makeswift site. This method is currently only used when calling getPageSnapshot and using Pages Router in Next.js.

Arguments

previewData
PreviewDataRequired

The preview data provided in getStaticProps.

Example

The following example sets up a catch all route where page snapshots are fetched from Makeswift using siteVersion and rendered using the <Page> component.

src/pages/[[...path]].tsx
1import {
2 GetStaticPathsResult,
3 GetStaticPropsContext,
4 GetStaticPropsResult,
5} from "next";
6
7import {
8 Page as MakeswiftPage,
9 PageProps as MakeswiftPageProps,
10 Makeswift,
11 type SiteVersion
12} from "@makeswift/runtime/next";
13
14import { client } from "../../../../../makeswift/client";
15import "../../../../../makeswift/components";
16
17type ParsedUrlQuery = { path?: string[] };
18
19export async function getStaticPaths(): Promise<
20 GetStaticPathsResult<ParsedUrlQuery>
21> {
22 const pages = await client.getPages().toArray();
23
24 return {
25 paths: pages.map((page) => ({
26 params: {
27 path: page.path.split("/").filter((segment) => segment !== ""),
28 },
29 })),
30 fallback: "blocking",
31 };
32}
33
34export type PageProps = MakeswiftPageProps & {
35 siteVersion: SiteVersion | null;
36};
37
38export async function getStaticProps({
39 params,
40 previewData,
41}: GetStaticPropsContext<ParsedUrlQuery>): Promise<
42 GetStaticPropsResult<PageProps>
43> {
44 const path = "/" + (params?.path ?? []).join("/");
45 const siteVersion = Makeswift.getSiteVersion(previewData);
46 const snapshot = await client.getPageSnapshot(path, {
47 siteVersion,
48 });
49
50 if (snapshot == null) return { notFound: true };
51
52 return {
53 props: {
54 snapshot,
55 siteVersion,
56 },
57 };
58}
59
60export default function Page({ snapshot }: MakeswiftPageProps) {
61 return <MakeswiftPage snapshot={snapshot} />;
62}