-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
505d945
commit 8f1f1de
Showing
8 changed files
with
755 additions
and
214 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { type GetStaticPaths, type InferGetStaticPropsType } from 'next' | ||
|
||
import { directusClient } from '@src/apollo-client' | ||
import { CustomComponents } from '@src/components/custom-page/common' | ||
import { FooterVariant } from '@src/components/FooterFull' | ||
import { | ||
ResourcePageDocument, | ||
type ResourcePageQuery, | ||
type ResourcePageQueryVariables, | ||
ResourcesPageSlugsDocument, | ||
type ResourcesPageSlugsQuery, | ||
type ResourcesPageSlugsQueryVariables, | ||
} from '@src/generated/graphqlDirectus' | ||
import { propsWithGlobalSettings } from '@src/utils/getGlobalProps' | ||
|
||
export default function Resource({ | ||
resourceInfo, | ||
}: InferGetStaticPropsType<typeof getStaticProps>) { | ||
return <CustomComponents components={resourceInfo.components ?? []} /> | ||
} | ||
|
||
export const getStaticPaths: GetStaticPaths = async () => { | ||
const { data, error } = await directusClient.query< | ||
ResourcesPageSlugsQuery, | ||
ResourcesPageSlugsQueryVariables | ||
>({ | ||
query: ResourcesPageSlugsDocument, | ||
}) | ||
|
||
if (error) { | ||
console.error('GraphQL query error in static:', error) | ||
} | ||
|
||
return { | ||
paths: data.resource_pages.map((page) => ({ | ||
params: { resource: page.slug }, | ||
})), | ||
fallback: 'blocking', | ||
} | ||
} | ||
|
||
export const getStaticProps = async (context) => { | ||
const slug = | ||
typeof context?.params?.resource === 'string' | ||
? context?.params?.resource | ||
: null | ||
|
||
if (!slug) { | ||
return { notFound: true } | ||
} | ||
|
||
const { data, error } = await directusClient.query< | ||
ResourcePageQuery, | ||
ResourcePageQueryVariables | ||
>({ | ||
query: ResourcePageDocument, | ||
variables: { slug }, | ||
}) | ||
|
||
if (error) { | ||
console.error('GraphQL query error in static: ', error) | ||
} | ||
const resourceInfo = data.resource_pages?.[0] || null | ||
|
||
if (!resourceInfo) { | ||
return { notFound: true } | ||
} | ||
|
||
return propsWithGlobalSettings({ | ||
metaTitle: resourceInfo?.dropdown_title ?? '', | ||
metaDescription: '', | ||
footerVariant: FooterVariant.kitchenSink, | ||
resourceInfo, | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.