Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/Footer/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Container } from "../";

export default function Footer() {
return (
<div className={styles.container}>
<footer className={styles.container}>
<Container>
<div>
<svg width="118" height="37" viewBox="0 0 118 37" fill="none">
Expand Down Expand Up @@ -55,6 +55,6 @@ export default function Footer() {
</div>
</div>
</Container>
</div>
</footer>
);
}
43 changes: 43 additions & 0 deletions components/PostPreview/PostPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Image from "next/image";
import Avatar from "../../components/avatar";
import DateFormatter from "../../components/date-formatter";
import CoverImage from "../../components/cover-image";
import Link from "next/link";

import styles from "./PostPreview.module.css";

export default function PostPreview({
title,
coverImage,
date,
excerpt,
author,
slug,
}) {
return (
<div className={styles.container}>
<Link as={`/posts/${slug}`} href="/posts/[slug]">
<a className={styles.postLink} aria-label={title}>
<Image
src={coverImage}
alt={`Cover Image for ${title}`}
className={styles.image}
height={350}
width={350}
/>

<div>
<div className={styles.pill}>
<p>Tech</p>
</div>
<h3>{title}</h3>
<div>
<p>{excerpt}</p>
<Avatar name={author.name} picture={author.picture} />
</div>
</div>
</a>
</Link>
</div>
);
}
29 changes: 29 additions & 0 deletions components/PostPreview/PostPreview.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.container {
--h3: var(--h4);
}

.container h3 {
line-height: 1.5;
margin-top: 16px;
}

.postLink {
color: var(--textColor);
text-decoration: none;
transition: none;
}

.image {
border-radius: 60px;
}

.pill {
--textColor: var(--pink);
height: 32px;
width: 90px;
display: flex;
justify-content: center;
background-color: #ffd3f5;
border-radius: 50px;
margin: 26px 0 0;
}
1 change: 1 addition & 0 deletions components/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as Footer } from "./Footer/Footer";
export { default as Container } from "./Container/Container";
export { default as PostPreview } from "./PostPreview/PostPreview";
16 changes: 2 additions & 14 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { getAllPosts } from "../lib/api";
import Head from "next/head";
import { CMS_NAME } from "../lib/constants";

import { CallToAction } from "../sections";
import { CallToAction, Blog } from "../sections";

export default function Index({ allPosts }) {
const heroPost = allPosts[0];
const morePosts = allPosts.slice(1);
return (
<>
<Layout>
Expand All @@ -20,18 +18,8 @@ export default function Index({ allPosts }) {
</Head>
<Container>
<Intro />
{heroPost && (
<HeroPost
title={heroPost.title}
coverImage={heroPost.coverImage}
date={heroPost.date}
author={heroPost.author}
slug={heroPost.slug}
excerpt={heroPost.excerpt}
/>
)}
{morePosts.length > 0 && <MoreStories posts={morePosts} />}
</Container>
<Blog posts={allPosts} />
<CallToAction />
</Layout>
</>
Expand Down
60 changes: 29 additions & 31 deletions pages/posts/[slug].js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { useRouter } from 'next/router'
import ErrorPage from 'next/error'
import Container from '../../components/container'
import PostBody from '../../components/post-body'
import Header from '../../components/header'
import PostHeader from '../../components/post-header'
import Layout from '../../components/layout'
import { getPostBySlug, getAllPosts } from '../../lib/api'
import PostTitle from '../../components/post-title'
import Head from 'next/head'
import { CMS_NAME } from '../../lib/constants'
import markdownToHtml from '../../lib/markdownToHtml'
import { useRouter } from "next/router";
import ErrorPage from "next/error";
import Container from "../../components/container";
import PostBody from "../../components/post-body";
import Header from "../../components/header";
import PostHeader from "../../components/post-header";
import Layout from "../../components/layout";
import { getPostBySlug, getAllPosts } from "../../lib/api";
import PostTitle from "../../components/post-title";
import Head from "next/head";
import { CMS_NAME } from "../../lib/constants";
import markdownToHtml from "../../lib/markdownToHtml";

export default function Post({ post, morePosts, preview }) {
const router = useRouter()
const router = useRouter();
if (!router.isFallback && !post?.slug) {
return <ErrorPage statusCode={404} />
return <ErrorPage statusCode={404} />;
}
return (
<Layout preview={preview}>
Expand All @@ -26,9 +26,7 @@ export default function Post({ post, morePosts, preview }) {
<>
<article className="mb-32">
<Head>
<title>
{post.title} | Next.js Blog Example with {CMS_NAME}
</title>
<title>{post.title}</title>
<meta property="og:image" content={post.ogImage.url} />
</Head>
<PostHeader
Expand All @@ -43,20 +41,20 @@ export default function Post({ post, morePosts, preview }) {
)}
</Container>
</Layout>
)
);
}

export async function getStaticProps({ params }) {
const post = getPostBySlug(params.slug, [
'title',
'date',
'slug',
'author',
'content',
'ogImage',
'coverImage',
])
const content = await markdownToHtml(post.content || '')
"title",
"date",
"slug",
"author",
"content",
"ogImage",
"coverImage",
]);
const content = await markdownToHtml(post.content || "");

return {
props: {
Expand All @@ -65,20 +63,20 @@ export async function getStaticProps({ params }) {
content,
},
},
}
};
}

export async function getStaticPaths() {
const posts = getAllPosts(['slug'])
const posts = getAllPosts(["slug"]);

return {
paths: posts.map((post) => {
return {
params: {
slug: post.slug,
},
}
};
}),
fallback: false,
}
};
}
3 changes: 3 additions & 0 deletions public/images/blogbottom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/images/blogtop.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions sections/Blog/Blog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { PostPreview } from "../../components";

import styles from "./Blog.module.css";

export default function Blog({ posts }) {
return (
<section className={styles.container}>
<div className={styles.title}>
<h2>Reading Recomendation</h2>
<p>Read our latest posts</p>
</div>

<div className={styles.grid}>
{posts.map(({ title, coverImage, date, excerpt, slug, author }) => {
return (
<div className={styles.postContainer}>
<PostPreview
title={title}
coverImage={coverImage}
date={date}
excerpt={excerpt}
slug={slug}
title={title}
author={author}
/>
</div>
);
})}
</div>
{/* <button>See More</button> */}
</section>
);
}
49 changes: 49 additions & 0 deletions sections/Blog/Blog.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.container {
margin-top: 350px;
margin-bottom: 400px;
background: var(--white);
padding: 40px 0;
position: relative;
}

.container::before {
content: "";
background-image: url("/images/blogtop.svg");
background-size: cover;
position: absolute;
left: 0;
right: 0;
height: 350px;
top: -348px;
}

.container::after {
content: "";
background-image: url("/images/blogbottom.svg");
background-size: cover;
position: absolute;
left: 0;
right: 0;
height: 400px;
bottom: -398px;
}

.title {
flex-direction: column;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 40px;
}

.postContainer {
display: flex;
justify-content: center;
}

.grid {
display: grid;
grid-template-columns: 350px 350px 350px;
gap: 30px;
justify-content: center;
}
2 changes: 1 addition & 1 deletion sections/CallToAction/CallToAction.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.container {
text-align: center;
--h4: var(--h2);
margin-bottom: 100px;
padding: 100px 0;
}

.container > h4 {
Expand Down
1 change: 1 addition & 0 deletions sections/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as CallToAction } from "./CallToAction/CallToAction";
export { default as Blog } from "./Blog/Blog";
3 changes: 2 additions & 1 deletion styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
--purple: #480198;
--black: #231f20;
--grey: #d1d3d4;
--lightGrey: #f4f4f4;
--white: #ffffff;

/* Usage */
--background: var(--grey);
--background: var(--lightGrey);
--lineColor: var(--grey);
--textColor: var(--black);
--hColor: var(--black);
Expand Down