diff --git a/src/app/blog/[slug]/page.tsx b/src/app/blog/[slug]/page.tsx index 4c91bc1..91a3809 100644 --- a/src/app/blog/[slug]/page.tsx +++ b/src/app/blog/[slug]/page.tsx @@ -1,8 +1,9 @@ import { getAllPosts, getPostBySlug } from "@/lib/posts"; +import { BackButton } from "@/components/ui/buttons"; +import { notFound } from 'next/navigation'; import { remark } from "remark"; import html from "remark-html"; import Link from "next/link"; -import { notFound } from 'next/navigation'; type Props = { params: Promise<{ slug: string }>; @@ -46,9 +47,7 @@ export default async function PostPage({ params }: Props) { /> diff --git a/src/app/blog/page.tsx b/src/app/blog/page.tsx index ddd483b..e6751f4 100644 --- a/src/app/blog/page.tsx +++ b/src/app/blog/page.tsx @@ -1,6 +1,6 @@ -import Link from "next/link"; -import Image from "next/image"; import { getAllPosts } from "@/lib/posts"; +import { BackButton } from "@/components/ui/buttons"; +import Link from "next/link"; export default async function BlogPage() { const posts = getAllPosts(); @@ -8,6 +8,9 @@ export default async function BlogPage() { return (
+
+ +
+ +
); } diff --git a/src/components/ui/buttons.tsx b/src/components/ui/buttons.tsx index 06c9919..9893a83 100644 --- a/src/components/ui/buttons.tsx +++ b/src/components/ui/buttons.tsx @@ -1,4 +1,7 @@ +"use client"; import Link from "next/link"; +import { useRouter } from "next/navigation"; +import React from "react"; export function GithubButton({ sublink }: { sublink: string }) { return ( @@ -15,7 +18,7 @@ export function GithubButton({ sublink }: { sublink: string }) { ); } -export function BookButton({ link, children }: { link: string, children: React.ReactNode }) { +export function BookButton({ link, children }: { link: string; children: React.ReactNode }) { return ( {children} ); +} + +export function BackButton({ href, label = "Back" }: { href?: string; label?: string }) { + const router = useRouter(); + + const handleClick = (e: React.MouseEvent) => { + e.preventDefault(); + if (href) { + router.push(href); + } else { + router.back(); + } + }; + + return ( + + ); } \ No newline at end of file