From 8868d7f586dae490ee3c104cdcab2947acf19b3d Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 27 Feb 2025 23:42:24 -0600 Subject: [PATCH] feat: enhance blog post page with markdown rendering and related posts --- .../website/app/[locale]/blog/[slug]/page.tsx | 193 ++++++++++++++---- apps/website/lib/ghost.ts | 10 +- apps/website/locales/en.json | 3 +- apps/website/locales/fr.json | 3 +- apps/website/locales/zh-Hans.json | 3 +- apps/website/next.config.js | 2 + package.json | 11 +- pnpm-lock.yaml | 157 ++++++++++++++ 8 files changed, 330 insertions(+), 52 deletions(-) diff --git a/apps/website/app/[locale]/blog/[slug]/page.tsx b/apps/website/app/[locale]/blog/[slug]/page.tsx index fe153bd..92f0a66 100644 --- a/apps/website/app/[locale]/blog/[slug]/page.tsx +++ b/apps/website/app/[locale]/blog/[slug]/page.tsx @@ -5,6 +5,11 @@ import { getTranslations } from "next-intl/server"; import Image from "next/image"; import Link from "next/link"; import { notFound } from "next/navigation"; +import type { DetailedHTMLProps, HTMLAttributes } from "react"; +import ReactMarkdown from "react-markdown"; +import type { Components } from "react-markdown"; +import rehypeRaw from "rehype-raw"; +import remarkGfm from "remark-gfm"; type Props = { params: { locale: string; slug: string }; @@ -52,6 +57,10 @@ export default async function BlogPostPage({ params }: Props) { const { locale, slug } = params; const t = await getTranslations({ locale, namespace: "blog" }); const post = await getPost(slug); + const allPosts = await getPosts(); + + // Get related posts (excluding current post) + const relatedPosts = allPosts.filter((p) => p.id !== post?.id).slice(0, 3); // Show only 3 related posts if (!post) { notFound(); @@ -63,6 +72,50 @@ export default async function BlogPostPage({ params }: Props) { day: "numeric", }); + const components: Partial = { + h1: ({ node, ...props }) => ( +

+ ), + h2: ({ node, ...props }) => ( +

+ ), + h3: ({ node, ...props }) => ( +

+ ), + p: ({ node, ...props }) => ( +

+ ), + a: ({ node, href, ...props }) => ( + + ), + ul: ({ node, ...props }) => ( +