forked from vercel/next.js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update cms-makeswift example (vercel#41005)
Makeswift now uses Next.js' Preview Mode so there's no need for a preview route. It also supports automatic on-demand revalidation with the introduction of the Makeswift API handler. ## Documentation / Examples - [x] Make sure the linting passes by running `pnpm lint` - [x] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
- Loading branch information
1 parent
6d18776
commit 4b7900a
Showing
6 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { MakeswiftApiHandler } from '@makeswift/runtime/next' | ||
|
||
export default MakeswiftApiHandler(process.env.MAKESWIFT_SITE_API_KEY!) |
This file was deleted.
Oops, something went wrong.