-
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
Showing
1 changed file
with
49 additions
and
62 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 |
---|---|---|
@@ -1,86 +1,73 @@ | ||
// import { Metadata, ResolvingMetadata } from 'next'; | ||
// import { | ||
// getStoryblokApi, ISbStoriesParams, StoryblokClient, StoryblokStory, | ||
// } from '@storyblok/react/rsc'; | ||
// import { resolveRelations } from '@/utilities/resolveRelations'; | ||
// import { getPageMetadata } from '@/utilities/getPageMetadata'; | ||
// import { notFound } from 'next/navigation'; | ||
type PathsType = { | ||
slug: string[]; | ||
}; | ||
import { Metadata } from 'next'; | ||
import { getStoryblokApi, ISbStoriesParams, StoryblokClient } from '@storyblok/react/rsc'; | ||
import StoryblokStory from '@storyblok/react/story'; | ||
import { resolveRelations } from '@/utilities/resolveRelations'; | ||
import { getPageMetadata } from '@/utilities/getPageMetadata'; | ||
|
||
type Props = { | ||
params: { id: string, slug: string[] } | ||
searchParams: { [key: string]: string | string[] | undefined } | ||
} | ||
|
||
// Make sure to not export the below functions otherwise there will be a typescript error | ||
// https://github.com/vercel/next.js/discussions/48724 | ||
// const getStoryData = async (params: { slug: string[] }) => { | ||
// const activeEnv = process.env.NODE_ENV || 'development'; | ||
// let slug: string = params.slug ? params.slug.join('/') : ''; | ||
// let sbParams: ISbStoriesParams = { | ||
// version: activeEnv === 'development' ? 'draft' : 'published', | ||
// cv: activeEnv === 'development' ? Date.now() : undefined, | ||
// resolve_relations: resolveRelations, | ||
// }; | ||
// const storyblokApi: StoryblokClient = getStoryblokApi(); | ||
const activeEnv = process.env.NODE_ENV || 'development'; | ||
|
||
// try { | ||
// const story = await storyblokApi.get(`cdn/stories/${slug}`, sbParams); | ||
// return story; | ||
// } catch (error) { | ||
// notFound(); | ||
// } | ||
// type PathsType = { | ||
// slug: string[]; | ||
// }; | ||
|
||
const Page = async ({ params }: Props) => { | ||
// const { data } = await getStoryData(params); | ||
// const bridgeOptions = { resolveRelations }; | ||
let slug: string = params.slug ? params.slug.join('/') : ''; | ||
|
||
return ( | ||
<> | ||
<h1>{params.slug}</h1> | ||
<p>Aaaaaah yeah. Server content.</p> | ||
</> | ||
); | ||
type ParamsType = { | ||
slug: string[]; | ||
}; | ||
|
||
/** | ||
* Generate metadata for the inside pages. | ||
*/ | ||
// export async function generateMetadata({ params }: Props, parent: ResolvingMetadata): Promise<Metadata> { | ||
// const { data } = await getStoryData(params); | ||
// const blok = data.story.content; | ||
// let slug: string = params.slug ? params.slug.join('/') : ''; | ||
// const meta = getPageMetadata({ blok, slug }); | ||
// return meta; | ||
// } | ||
|
||
/** | ||
* Generate static paths for the inside pages. | ||
*/ | ||
// export async function generateStaticParams(): Promise<any[]> { | ||
// const activeEnv = process.env.NODE_ENV || 'development'; | ||
// async function generateStaticParams() { | ||
// const storyblokApi: StoryblokClient = getStoryblokApi(); | ||
// let sbParams: ISbStoriesParams = { | ||
// version: activeEnv === 'development' ? 'draft' : 'published', | ||
// cv: activeEnv === 'development' ? Date.now() : undefined, | ||
// }; | ||
|
||
// const { data: { links } } = await storyblokApi.get('cdn/links', sbParams); | ||
// let paths: PathsType[] = []; | ||
|
||
// Object.keys(links).forEach((linkKey) => { | ||
// if (links[linkKey].is_folder || links[linkKey].slug === 'home') { | ||
// return; | ||
// } | ||
// const slug:string = links[linkKey].slug; | ||
// const slug: string = links[linkKey].slug; | ||
// let splittedSlug = slug.split('/'); | ||
// paths.push({ slug: splittedSlug }); | ||
// }); | ||
|
||
// // Return a list of paths and no fallback. | ||
// return paths; | ||
// }; | ||
|
||
export default Page; | ||
// Make sure to not export the below functions otherwise there will be a typescript error | ||
// https://github.com/vercel/next.js/discussions/48724 | ||
async function getStoryData(params: { slug: string[] }) { | ||
let slug: string = params.slug ? params.slug.join('/') : ''; | ||
let sbParams: ISbStoriesParams = { | ||
version: activeEnv === 'development' ? 'draft' : 'published', | ||
cv: activeEnv === 'development' ? Date.now() : undefined, | ||
resolve_relations: resolveRelations, | ||
}; | ||
|
||
const storyblokApi: StoryblokClient = getStoryblokApi(); | ||
const story = await storyblokApi?.get(`cdn/stories/${slug}`, sbParams); | ||
|
||
return story; | ||
}; | ||
|
||
export async function generateMetadata({ params }: { params: ParamsType }): Promise<Metadata> { | ||
const { data } = await getStoryData(params); | ||
const blok = data.story.content; | ||
|
||
let slug: string = params.slug ? params.slug.join('/') : ''; | ||
const meta = getPageMetadata({ blok, slug }); | ||
|
||
return meta; | ||
} | ||
|
||
export default async function Page({ params }: { params: ParamsType }) { | ||
const { data } = await getStoryData(params); | ||
const bridgeOptions = { resolveRelations }; | ||
let slug: string = params.slug ? params.slug.join('/') : ''; | ||
|
||
return ( | ||
<StoryblokStory story={data.story} bridgeOptions={bridgeOptions} slug={slug} /> | ||
); | ||
}; |