-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(saas): blog slug page, fetch blog according to slug
- Loading branch information
1 parent
009d354
commit 5dadb94
Showing
7 changed files
with
88 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,59 @@ | ||
import { WebPageWrapper } from "@/app/(web)/_components/general-components"; | ||
import { Toc } from "@/components/toc"; | ||
import { siteUrls } from "@/config/urls"; | ||
import { getBlogs } from "@/server/actions/blog"; | ||
import { format } from "date-fns"; | ||
import Image from "next/image"; | ||
import { notFound, redirect } from "next/navigation"; | ||
|
||
type BlogSlugPageProps = { | ||
params: { | ||
slug: string[]; | ||
}; | ||
}; | ||
|
||
export default function BlogSlugPage({ params }: BlogSlugPageProps) { | ||
export default async function BlogSlugPage({ params }: BlogSlugPageProps) { | ||
if (!params.slug) { | ||
return redirect(siteUrls.blog); | ||
} | ||
|
||
const slug = params.slug.join("/"); | ||
|
||
const blog = (await getBlogs()).find((b) => b.metaData.slug === slug); | ||
|
||
if (!blog) { | ||
return notFound(); | ||
} | ||
|
||
return ( | ||
<WebPageWrapper> | ||
<div className="w-full"> | ||
<h1>Blog Slug Page</h1> | ||
{JSON.stringify(params)} | ||
</div> | ||
<WebPageWrapper className="relative max-w-3xl flex-row items-start gap-8"> | ||
<article className="w-full space-y-10"> | ||
<div className="space-y-4"> | ||
<h1 className="scroll-m-20 font-heading text-4xl font-bold"> | ||
{blog.metaData.title} | ||
</h1> | ||
|
||
<div className="relative aspect-video max-h-[350px] w-full overflow-hidden rounded-md bg-muted/60"> | ||
<Image | ||
src={blog.metaData.tumbnail} | ||
alt={blog.metaData.title} | ||
className="rounded-md" | ||
fill | ||
/> | ||
</div> | ||
<p className="text-sm text-muted-foreground"> | ||
{format(new Date(blog.metaData.publishedAt), "PPP")} •{" "} | ||
{blog.metaData.readTime} read | ||
</p> | ||
{blog.metaData.updatedAt && ( | ||
<p className="text-sm text-muted-foreground"> | ||
Last updated at{" "} | ||
{format(new Date(blog.metaData.updatedAt), "PPP")} | ||
</p> | ||
)} | ||
</div> | ||
{blog.content} | ||
</article> | ||
</WebPageWrapper> | ||
); | ||
} |
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
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