Skip to content

Commit

Permalink
Hm
Browse files Browse the repository at this point in the history
  • Loading branch information
devashish2024 committed Apr 25, 2024
1 parent 7fd401b commit 82c9bd8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 65 deletions.
65 changes: 65 additions & 0 deletions src/app/blog/[postSlug]/components/Article.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Image from "next/image";

export const Article = ({ post }) => {

return (
<div className="max-w-5xl xl:max-w-7xl xl:grid xl:grid-cols-[2fr_1fr] gap-12 mt-12 mb-24">
<aside className="mb-12 xl:order-2">
<Image
width="984"
height="554"
className="w-full rounded h-auto mb-6 xl:mb-12"
src={post.coverImage.url}
alt=""
/>
</aside>
<article className="w-full xl:order-1 mx-auto">
<h1 className="text-4xl font-bold mb-8">{post.title}</h1>
<div className="max-w-3xl flex items-center gap-4 mb-8">
<Image
width="48"
height="48"
className="w-12 h-auto rounded-full"
src={post.author.profilePicture}
alt=""
/>
<div>
<p className="text-lg font-bold mb-[.1rem]">{post.author.name}</p>
<ul className="flex gap-3">
<li className="text-sm">
<a
className="hover:underline hover:text-blue-500"
href="https://twitter.com/@ashishagr2024"
>
Twitter
</a>{" "}
<a
className="hover:underline hover:text-blue-500"
href="https://github.com/ashishagarwal2023"
>
GitHub
</a>
</li>
</ul>
</div>
</div>
<p className="italic text-zinc-300 mb-6">
Published on
{` `}
{new Date(post.publishedAt).toLocaleDateString("en-us", {
weekday: "long",
year: "numeric",
month: "short",
day: "numeric",
})}
</p>
<div
className="prose max-w-3xl prose-img:rounded text-white article_contents"
dangerouslySetInnerHTML={{
__html: post.content.html,
}}
/>
</article>
</div>
);
}
72 changes: 7 additions & 65 deletions src/app/blog/[postSlug]/page.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,27 @@
import Image from "next/image";
import { getPostBySlug, getAllPostSlugs } from "@/lib/posts";
import { Article } from "./components/Article";

export async function generateStaticParams() {
const slugs = await getAllPostSlugs();
return slugs.map((slug) => ({
postSlug: slug
postSlug: slug,
}));
}

export async function generateMetadata({
params,
}) {
export async function generateMetadata({ params }) {
const post = await getPostBySlug(params.postSlug);
return {
title: `${post.title} - Ashish Agarwal`,
description: post.seo?.description || `Read ${post.title} on Ashish Agarwal's Blog`,
description:
post.seo?.description || `Read ${post.title} on Ashish Agarwal's Blog`,
};
}

export default async function Post({ params }) {
const post = await getPostBySlug(params.postSlug);
return (
<>
<div className="max-w-5xl xl:max-w-7xl xl:grid xl:grid-cols-[2fr_1fr] gap-12 mt-12 mb-24">
<aside className="mb-12 xl:order-2">
<Image
width="984"
height="554"
className="w-full rounded h-auto mb-6 xl:mb-12"
src={post.coverImage.url}
alt=""
/>
</aside>
<article className="w-full xl:order-1 mx-auto">
<h1 className="text-4xl font-bold mb-8">{post.title}</h1>
<div className="max-w-3xl flex items-center gap-4 mb-8">
<Image
width="48"
height="48"
className="w-12 h-auto rounded-full"
src={post.author.profilePicture}
alt=""
/>
<div>
<p className="text-lg font-bold mb-[.1rem]">{post.author.name}</p>
<ul className="flex gap-3">
<li className="text-sm">
<a
className="hover:underline hover:text-blue-500"
href="https://twitter.com/@ashishagr2024"
>
Twitter
</a> {" "}
<a
className="hover:underline hover:text-blue-500"
href="https://github.com/ashishagarwal2023"
>
GitHub
</a>
</li>
</ul>
</div>
</div>
<p className="italic text-zinc-300 mb-6">
Published on
{` `}
{new Date(post.publishedAt).toLocaleDateString("en-us", {
weekday: "long",
year: "numeric",
month: "short",
day: "numeric",
})}
</p>
<div
className="prose max-w-3xl prose-img:rounded text-white article_contents"
dangerouslySetInnerHTML={{
__html: post.content.html,
}}
/>
</article>
</div>
<Article post={post} />
</>
);
}
}

0 comments on commit 82c9bd8

Please sign in to comment.