Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mastodon
GitHub Repository: mastodon/joinmastodon
Path: blob/main/utils/defaultStaticProps.ts
1006 views
1
import { GetStaticProps, GetStaticPropsContext } from "next"
2
import loadIntlMessages from "./loadIntlMessages"
3
4
type ReturnProps<Props extends Record<string, any>> = Props & {
5
intlMessages: Record<string, string>
6
}
7
8
export function withDefaultStaticProps<
9
Props extends Record<string, any> = Record<string, any>,
10
>(origin?: GetStaticProps<Props>): GetStaticProps<ReturnProps<Props>> {
11
return async (ctx: GetStaticPropsContext<ReturnProps<Props>>) => {
12
const { revalidate = 300, ...originResult } = origin
13
? await origin(ctx)
14
: {}
15
const originProps =
16
"props" in originResult ? originResult.props : ({} as Props)
17
18
return {
19
...originResult,
20
props: {
21
...(originProps as Props),
22
intlMessages: await loadIntlMessages(ctx),
23
},
24
revalidate: revalidate,
25
}
26
}
27
}
28
29