-
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.
SOEOPSFY24-419 | build out dynamic story page
- Loading branch information
1 parent
ac48e9a
commit 791611e
Showing
55 changed files
with
384 additions
and
286 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { fetchStoryData } from "@/utilities/fetchStoryData"; | ||
import { renderDynamicComponent } from "@/utilities/renderDynamicComponent"; | ||
import { StoryData } from "@/types/storyPage"; | ||
|
||
interface StoryPageProps { | ||
params: { storySlug: string }; | ||
} | ||
|
||
const StoryPage = async ({ params }: StoryPageProps) => { | ||
const storyData: StoryData | null = await fetchStoryData(params.storySlug); | ||
|
||
if (!storyData) { | ||
return <p>Story not found.</p>; | ||
} | ||
|
||
return ( | ||
<div> | ||
{storyData.map((block, index) => ( | ||
<div key={index}>{renderDynamicComponent(block.type, block.props)}</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
// Static generation for performance | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
export async function generateStaticParams() { | ||
const storiesDir = path.join(process.cwd(), "data/stories"); | ||
const files = await fs.promises.readdir(storiesDir); | ||
|
||
return files.map((file) => ({ | ||
storySlug: file.replace(".json", ""), | ||
})); | ||
} | ||
|
||
export default StoryPage; |
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 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,40 +1,44 @@ | ||
import React, { HTMLAttributes } from "react"; | ||
import { BgColorType, Container } from "@/components/Container"; | ||
import { MarginType, PaddingType } from "@/utilities/datasource"; | ||
import { cnb } from "cnbuilder"; | ||
import { OneCol } from "./OneCol"; | ||
|
||
type ColProps = HTMLAttributes<HTMLDivElement> & { | ||
children: React.ReactNode; | ||
isSidebar?: boolean; | ||
pt?: PaddingType; | ||
pb?: PaddingType; | ||
py?: PaddingType; | ||
mt?: MarginType; | ||
mb?: MarginType; | ||
my?: MarginType; | ||
leftItems: React.ReactNode; | ||
rightItems: React.ReactNode; | ||
columnWidth?: "sidebar" | "default"; | ||
isNarrow?: boolean; | ||
bgColor?: BgColorType; | ||
}; | ||
|
||
export const TwoCol = ({ | ||
children, | ||
leftItems, | ||
rightItems, | ||
className, | ||
isSidebar = false, | ||
columnWidth = "default", | ||
isNarrow, | ||
...props | ||
}: ColProps) => { | ||
let gridCols = "md:grid-cols-2"; | ||
if (columnWidth === "sidebar") { | ||
gridCols = "@6xl:grid-cols-2-1"; | ||
} | ||
|
||
return ( | ||
<Container | ||
{...props} | ||
className={cnb( | ||
"flex flex-col w-full max-w-full lg:flex-row gap-20", | ||
"w-full", | ||
{ | ||
"lg:*:w-1/2": !isSidebar, | ||
"lg:first:max-w-2/3 lg:last:max-w-1/3": isSidebar, | ||
"xl:mx-auto xl:w-900 2xl:w-1300": isNarrow, | ||
}, | ||
gridCols, | ||
className, | ||
)} | ||
mb={6} | ||
width="site" | ||
> | ||
{children} | ||
<OneCol>{leftItems}</OneCol> | ||
<OneCol>{rightItems}</OneCol> | ||
</Container> | ||
); | ||
}; |
Oops, something went wrong.