Download next.js/examples/cms-makeswift/pages/[[...path]].tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/cms-makeswift/pages/%5B%5B...path%5D%5D.tsx
- Command line
-
hf download 'hf://datasets/Devendra174/react-code-dataset/next.js/examples/cms-makeswift/pages/[[...path]].tsx'
-
curl -L -o '[[...path]].tsx' https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/cms-makeswift/pages/%5B%5B...path%5D%5D.tsx
1.31 kB
| 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} />; | |
| } | |