Skip to content

Commit d119b96

Browse files
feat: add recipe and post featuring on home page
1 parent c235af3 commit d119b96

File tree

6 files changed

+121
-15
lines changed

6 files changed

+121
-15
lines changed

app/page.tsx

+74-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
1+
import FeaturedShowcase from "@/components/FeaturedShowcase";
12
import InfoBox from "@/components/InfoBox";
23
import ExportedImage from "next-image-export-optimizer";
4+
import { Post, posts, Recipe, recipes } from "@content";
5+
import Card from "@/components/Card";
6+
import CardGrid from "@/components/CardGrid";
7+
import ArticleBlock from "@/components/ArticleBlock";
8+
import { dateSort } from "@/utils/utils";
39

410
export default function Home() {
11+
const featuredRecipes = recipes
12+
.filter((recipe: Recipe) => recipe.published && recipe.featured)
13+
.sort(dateSort)
14+
.slice(0, 4);
15+
16+
const featuredPosts = posts
17+
.filter((post: Post) => post.published && post.featured)
18+
.sort(dateSort)
19+
.slice(0, 4);
20+
21+
const gridFormat: [string, number, number, boolean][] = [
22+
["l", 1000, 4, true],
23+
["m", 500, 2, true],
24+
["s", 200, 1, true],
25+
];
26+
const margin: [number, number] = [15, 15];
27+
const containerPadding: [number, number] = [0, 0];
28+
529
return (
630
<>
731
<div className="home-hero">
@@ -10,24 +34,61 @@ export default function Home() {
1034
src="/home-hero.jpg"
1135
alt="Hero image"
1236
fill={true}
37+
priority={true}
1338
/>
1439
<h1>Welcome to my website!</h1>
1540
<div className="subtitle">Recipes, projects & more</div>
1641
</div>
1742
<div className="home-page">
18-
<InfoBox title="Note">
19-
<p>
20-
This is the new and improved version 2 of my website ! <br />I
21-
finally made the switch from plain old HTML/CSS/JS to using Next.js.
22-
This has allowed me to easily make this website a lot easier to
23-
manage: I can now add recipes and posts in simple MDX format, and
24-
they are formatted and added everywhere automatically.
25-
</p>
26-
<p>
27-
I{"'"}m still adding some functionalities but I transferred most of
28-
the original content already, and more will come !
29-
</p>
30-
</InfoBox>
43+
<div className="force-article">
44+
<InfoBox title="Note">
45+
<p>
46+
This is the new and improved version 2 of my website ! <br />I
47+
finally made the switch from plain old HTML/CSS/JS to using
48+
Next.js. This has allowed me to easily make this website a lot
49+
easier to manage: I can now add recipes and posts in simple MDX
50+
format, and they are formatted and added everywhere automatically.
51+
</p>
52+
<p>
53+
I{"'"}m still adding some functionalities but I transferred most
54+
of the original content already, and more will come !
55+
</p>
56+
</InfoBox>
57+
</div>
58+
<FeaturedShowcase title="Featured Recipes">
59+
<CardGrid
60+
gridFormat={gridFormat}
61+
margin={margin}
62+
containerPadding={containerPadding}
63+
>
64+
{featuredRecipes.map((recipe) => (
65+
<Card
66+
slug={recipe.slug}
67+
title={recipe.name}
68+
imageUrl={recipe.coverImage.src}
69+
key={recipe.slug}
70+
/>
71+
))}
72+
</CardGrid>
73+
</FeaturedShowcase>
74+
<FeaturedShowcase title="Featured Posts">
75+
<CardGrid
76+
gridFormat={gridFormat}
77+
margin={margin}
78+
containerPadding={containerPadding}
79+
>
80+
{featuredPosts.map((post: Post) => (
81+
<div className="article-block-card" key={post.slug}>
82+
<ArticleBlock
83+
article={post}
84+
disableTags={true}
85+
fillSpace={true}
86+
titleLevel={3}
87+
/>
88+
</div>
89+
))}
90+
</CardGrid>
91+
</FeaturedShowcase>
3192
</div>
3293
</>
3394
);

components/FeaturedShowcase.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Card from "./Card";
2+
import CardGrid from "./CardGrid";
3+
4+
export default function FeaturedShowcase({
5+
title,
6+
seeMoreLink,
7+
children,
8+
}: {
9+
title: string;
10+
seeMoreLink?: string;
11+
children: React.ReactElement;
12+
}) {
13+
return (
14+
<section className="featured-showcase">
15+
<h2>{title}</h2>
16+
{/* TODO: Add see more link */ }
17+
{children}
18+
</section>
19+
);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.featured-showcase {
2+
margin: 2rem 0;
3+
h2 {
4+
text-align: center;
5+
margin-bottom: 1.5rem;
6+
}
7+
}

styles/components/_index.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
@forward "info-box";
99
@forward "recipe-info";
1010
@forward "article-block";
11-
@forward "tag";
11+
@forward "tag";
12+
@forward "featured-showcase"

styles/pages/_home.scss

+16-1
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,20 @@
5757
}
5858
}
5959
.home-page {
60-
@include article-content;
60+
@include wide-content;
61+
62+
.force-article {
63+
@include article-content;
64+
margin-bottom: 0;
65+
@media screen and (max-width: 75rem) {
66+
margin-bottom: 0;
67+
}
68+
}
69+
70+
.article-block-card {
71+
border: solid 2px var(--border-color);
72+
border-radius: $border-radius;
73+
padding: 1rem;
74+
height: 100%;
75+
}
6176
}

velite.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const recipes = defineCollection({
3939
contentImage: s.image().optional(),
4040
date: s.isodate(),
4141
published: s.boolean().default(true),
42+
featured: s.boolean().default(false),
4243
tags: s.array(s.string()).optional(),
4344
yield: s.number(), // number of servings
4445
yieldUnit: s.string().optional(), // unit of the yield
@@ -66,6 +67,7 @@ const posts = defineCollection({
6667
description: s.string().max(200).optional(),
6768
date: s.isodate(),
6869
published: s.boolean().default(true),
70+
featured: s.boolean().default(false),
6971
tags: s.array(s.string()).default([]),
7072
body: s.mdx(),
7173
})

0 commit comments

Comments
 (0)