Skip to content

Commit

Permalink
SOEOPSFY24-419 | build out dynamic story page
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahongsf committed Jan 10, 2025
1 parent ac48e9a commit 791611e
Show file tree
Hide file tree
Showing 55 changed files with 384 additions and 286 deletions.
75 changes: 1 addition & 74 deletions app/example/story/card/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Container } from "@/components/Container";
import { FlexBox } from "@/components/FlexBox";
import { ThreeCol, TwoCol } from "@/components/Layout";
import { Masthead } from "@/components/Masthead";
import { StoryCard, StoryFeature, StoryPosterCard } from "@/components/Story";
import { Heading, Text } from "@/components/Typography";

import { StoryCard, StoryPosterCard } from "@/components/Story";
const ExampleCardPage = async () => {
return (
<div>
Expand All @@ -20,75 +16,6 @@ const ExampleCardPage = async () => {
href="/"
/>
</Container>
<ThreeCol>
<StoryCard
bgColor="blue"
heading="Lorem ipsum dolor sit amet consect hendrerit"
superhead="Change makers"
body="Quisque ante nunc, luctus nec aliquet in, gravida sed dui. Mauris posuere luctus varius."
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
chapter="Chapter 1"
/>
<StoryCard
heading="Lorem ipsum dolor sit amet consect hendrerit"
superhead="Change makers"
body="Quisque ante nunc, luctus nec aliquet in, gravida sed dui. Mauris posuere luctus varius."
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
/>
<StoryCard
heading="Lorem ipsum dolor sit amet consect hendrerit"
superhead="Change makers"
body="Quisque ante nunc, luctus nec aliquet in, gravida sed dui. Mauris posuere luctus varius."
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
/>
</ThreeCol>
<StoryFeature>
<TwoCol className="rs-mb-8 items-center">
<FlexBox direction="col">
<Heading size="f4" weight="normal" className="rs-mr-8">
Fundamental work in science and transformational breakthroughs for
one hundred years.
</Heading>
<Text className="order-first" mb={2} font="dm-mono">
Stories
</Text>
</FlexBox>
<StoryCard
superhead="Impact"
heading="Lorem ipsum dolor sit amet consect hendrerit"
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
className="max-w-full"
chapter="1985 - 1994"
/>
</TwoCol>
<ThreeCol>
<StoryCard
superhead="Change makers"
heading="The Foundation of a New Era in Engineering"
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
chapter="Innovation"
/>
<StoryCard
superhead="Change makers"
heading="Computation, outer space, the nanoscale, and the fragility of planet Earth"
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
chapter="1985 - 1994"
/>
<StoryCard
superhead="Change makers"
heading="Mae Jemison: “We each get a chance to choose our own path”"
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
chapter="1985 - 1994"
/>
</ThreeCol>
</StoryFeature>
<StoryPosterCard
heading="The foundation of a new era in engineering"
superhead="100 Years of Impact"
Expand Down
42 changes: 0 additions & 42 deletions app/example/story/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Heading, Text } from "@/components/Typography";
import { Masthead } from "@/components/Masthead";
import { Container } from "@/components/Container";
import { ContributeStoryBanner } from "@/components/ContributeStoryBanner";
import { TimelineSidebar } from "@/components/Timeline";
import { StoryImpactBanner } from "@/components/Story";
import { TwoCol } from "@/components/Layout";

const ExampleStoryPage = async () => {
return (
Expand All @@ -19,44 +15,6 @@ const ExampleStoryPage = async () => {
src="/soe-centennial-nextjs/assets/images/lt-flynn-1994.jpeg"
caption="Caption/credit lorem ipsum dolar sit amet vestibulum perimentium"
/>
<TwoCol isSidebar>
<Container width="wysiwyg">
<Text className="type-3 intro-text">
Overview style lorem ipsum dolar sit amet vestibulum parimentium
elit rhoncus donec. Scelerisque urna et euismod in daphibus nec leo
euismod nisi, pharetra raesent nec. Aliquam dignissim nisi convalis
quis, leo vestibulum duis euismod.
</Text>
<Text className="big-paragraph">
Long copy paragraph text style raesent nec dapibus odio. Aliquam
dignissim nisi nisi, pharetra faucibus elit rhoncus in. Donec
efficitur scelerisque urna et sollicitudin. Donec euismod enim a dui
convallis, quis suscipit leo vestibulum. Duis aliquam euismod enim,
sit amet
</Text>
<Heading>Header Two</Heading>
<Text className="big-paragraph">
Fusce sem enim, tempus nec massa id, mollis faucibus sem. Ut ipsum
erat, imperdiet eu fermentum sed in text link. Praesent nec dapibus
odio. Aliquam dignissim nisi nisi, pharetra faucibus elit rhoncus
in. Donec efficitur scelerisque urna et sollicitudin. Duis aliquam
euismod enim, sit amet in text link hover state. Aliquam sodales
consequat arcu in egestas. Aliquam condimentum viverra eros.Donec
efficitur scelerisque urna et sollicitudin. Duis aliquam euismod
enim, sit amet.
</Text>
<Heading as="h3">Header Three</Heading>
<Text className="big-paragraph">
Aenean sollicitudin facilisis ex, in tincidunt velit sodales ac.
Nullam consequat leo ut sem pharetra, a fringilla massa commodo.
Etiam molestie, justo nec congue ultricies, augue massa tempus ante,
nec sagittis dui tellus ac lectus. Duis aliquam euismod enim, sit
amet lobortis ante porttitor. Donec efficitur scelerisque urna et
sollicitudin. Duis aliquam euismod enim, sit amet.
</Text>
</Container>
<TimelineSidebar />
</TwoCol>
<ContributeStoryBanner />
</div>
);
Expand Down
73 changes: 11 additions & 62 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { Masthead } from "@/components/Masthead";
import { TimelineCard } from "@/components/Timeline";
import { PageTitle } from "@/components/PageTitle";
import { TimelineFeature } from "@/components/Timeline/TimelineFeature";
import { ThreeCol, TwoCol } from "@/components/Layout";
import { StoryCard } from "@/components/Story";
import { StoryCard, StoryPosterCard } from "@/components/Story";
import { Container } from "@/components/Container";
import { StoryFeature } from "@/components/Story/StoryFeature";
import { Heading } from "@/components/Typography";
import Metadata from "@/components/Layout/Metadata";

export default function Home() {
Expand All @@ -26,6 +23,16 @@ export default function Home() {
/>
<Masthead isLight bgColor="fog-light" />
<PageTitle heading="100 years of" bigText="Impact" />
<StoryPosterCard
hasBgImage
heading="The foundation of a new era in engineering"
superhead="100 Years of Impact"
body="The education of engineers had been a founding intention for the university, with an engineering curriculum in place since its inception."
src="https://res.cloudinary.com/dsqi5touf/image/upload/v1734567986/1926_-_The_largest_university_electrical_lab_of_its_time_c3orrt.jpg"
caption="Caption/credit lorem ipsum dolar sit amet vestibulum perimentium"
chapter="Chapter 1"
link="/"
/>
<TimelineCard
isHorizontal
heading="The first African-American woman in space"
Expand Down Expand Up @@ -62,64 +69,6 @@ export default function Home() {
href="/"
/>
</Container>
<ThreeCol>
<StoryCard
heading="Lorem ipsum dolor sit amet consect hendrerit"
superhead="Change makers"
body="Quisque ante nunc, luctus nec aliquet in, gravida sed dui. Mauris posuere luctus varius."
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
/>
<StoryCard
heading="Lorem ipsum dolor sit amet consect hendrerit"
superhead="Change makers"
body="Quisque ante nunc, luctus nec aliquet in, gravida sed dui. Mauris posuere luctus varius."
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
/>
<StoryCard
heading="Lorem ipsum dolor sit amet consect hendrerit"
superhead="Change makers"
body="Quisque ante nunc, luctus nec aliquet in, gravida sed dui. Mauris posuere luctus varius."
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
/>
</ThreeCol>
<StoryFeature>
<TwoCol className="rs-mb-8 items-center">
<Heading size={5} weight="normal" className="rs-mr-8">
Fundamental work in science and transformational breakthroughs for
one hundred years.
</Heading>
<StoryCard
superhead="Impact"
heading="Lorem ipsum dolor sit amet consect hendrerit"
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
className="max-w-full"
/>
</TwoCol>
<ThreeCol>
<StoryCard
superhead="Innovation"
heading="The Foundation of a New Era in Engineering"
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
/>
<StoryCard
superhead="1975 - 1984"
heading="Computation, outer space, the nanoscale, and the fragility of planet Earth"
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
/>
<StoryCard
superhead="1985 - 1994"
heading="Mae Jemison: “We each get a chance to choose our own path”"
imageUrl="https://placecats.com/neo_banana/300/200"
href="/"
/>
</ThreeCol>
</StoryFeature>
</div>
);
}
38 changes: 38 additions & 0 deletions app/stories/[storySlug]/page.tsx
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;
12 changes: 4 additions & 8 deletions components/Layout/OneCol.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import React, { HTMLAttributes } from "react";
import { BgColorType, Container } from "@/components/Container";
import { MarginType, PaddingType } from "@/utilities/datasource";
import { cnb } from "cnbuilder";

type ColProps = HTMLAttributes<HTMLDivElement> & {
children: React.ReactNode;
pt?: PaddingType;
pb?: PaddingType;
py?: PaddingType;
mt?: MarginType;
mb?: MarginType;
my?: MarginType;
bgColor?: BgColorType;
};

export const OneCol = ({ children, className, ...props }: ColProps) => {
return (
<Container
{...props}
className={cnb("flex flex-col items-center *:max-w-[725px]", className)}
className={cnb(
"space-y-16 @container flex flex-col items-center *:max-w-[725px]",
className,
)}
mb={6}
>
{children}
Expand Down
7 changes: 0 additions & 7 deletions components/Layout/ThreeCol.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import React, { HTMLAttributes } from "react";
import { BgColorType, Container } from "@/components/Container";
import { MarginType, PaddingType } from "@/utilities/datasource";
import { cnb } from "cnbuilder";

type ColProps = HTMLAttributes<HTMLDivElement> & {
children: React.ReactNode;
pt?: PaddingType;
pb?: PaddingType;
py?: PaddingType;
mt?: MarginType;
mb?: MarginType;
my?: MarginType;
bgColor?: BgColorType;
};

Expand Down
36 changes: 20 additions & 16 deletions components/Layout/TwoCol.tsx
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>
);
};
Loading

0 comments on commit 791611e

Please sign in to comment.