File size: 1,313 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import "../lib/makeswift/register-components";
import { Makeswift } from "@makeswift/runtime/next";
import {
GetStaticPathsResult,
GetStaticPropsContext,
GetStaticPropsResult,
} from "next";
import {
Page as MakeswiftPage,
PageProps as MakeswiftPageProps,
} from "@makeswift/runtime/next";
type ParsedUrlQuery = { path?: string[] };
export async function getStaticPaths(): Promise<
GetStaticPathsResult<ParsedUrlQuery>
> {
const makeswift = new Makeswift(process.env.MAKESWIFT_SITE_API_KEY!);
const pages = await makeswift.getPages();
return {
paths: pages.map((page) => ({
params: {
path: page.path.split("/").filter((segment) => segment !== ""),
},
})),
fallback: "blocking",
};
}
type Props = MakeswiftPageProps;
export async function getStaticProps(
ctx: GetStaticPropsContext<ParsedUrlQuery>,
): Promise<GetStaticPropsResult<Props>> {
const makeswift = new Makeswift(process.env.MAKESWIFT_SITE_API_KEY!);
const path = "/" + (ctx.params?.path ?? []).join("/");
const snapshot = await makeswift.getPageSnapshot(path, {
preview: ctx.preview,
});
if (snapshot == null) return { notFound: true };
return { props: { snapshot } };
}
export default function Page({ snapshot }: Props) {
return <MakeswiftPage snapshot={snapshot} />;
}
|