Skip to content

Commit 034aca0

Browse files
author
iitzIrFan
committed
feat: make blog cards clickable for improved navigation
1 parent 65ff8c3 commit 034aca0

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

src/pages/blogs/index.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
33
import Layout from "@theme/Layout";
44
import Link from "@docusaurus/Link";
5+
import { useHistory } from "@docusaurus/router";
56
import blogs from "../../database/blogs/index";
67
import Head from "@docusaurus/Head";
78
import { getAuthorProfiles } from "../../utils/authors";
@@ -233,6 +234,8 @@ export default function Blogs() {
233234

234235
const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
235236
const authors = getAuthorProfiles(blog.authors || []);
237+
const history = useHistory();
238+
const blogPath = `/blog/${blog.slug}`;
236239

237240
// Tags — use blog.tags if present, fallback to blog.category as single tag
238241
const tags: string[] =
@@ -243,7 +246,19 @@ const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
243246
: [];
244247

245248
return (
246-
<div className="article-card">
249+
<div
250+
className="article-card"
251+
role="link"
252+
tabIndex={0}
253+
aria-label={`Read ${blog.title}`}
254+
onClick={() => history.push(blogPath)}
255+
onKeyDown={(event) => {
256+
if (event.key === "Enter" || event.key === " ") {
257+
event.preventDefault();
258+
history.push(blogPath);
259+
}
260+
}}
261+
>
247262
{/* ── Image ── */}
248263
<div className="card-image">
249264
<img src={blog.image} alt={blog.title} loading="lazy" />
@@ -253,9 +268,7 @@ const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
253268
<div className="card-content">
254269
{/* Title */}
255270
<h3 className="card-title">
256-
<Link to={`/blog/${blog.slug}`} className="card-title-link">
257-
{blog.title}
258-
</Link>
271+
<span className="card-title-link">{blog.title}</span>
259272
</h3>
260273

261274
{/* Description */}
@@ -302,6 +315,7 @@ const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
302315
target="_blank"
303316
rel="noopener noreferrer"
304317
title={author.name}
318+
onClick={(event) => event.stopPropagation()}
305319
>
306320
{author.imageUrl ? (
307321
<img
@@ -340,6 +354,7 @@ const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
340354
target="_blank"
341355
rel="noopener noreferrer"
342356
title={author.name}
357+
onClick={(event) => event.stopPropagation()}
343358
>
344359
{author.name}
345360
</Link>
@@ -354,7 +369,7 @@ const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
354369
</div>
355370

356371
{/* Read link */}
357-
<Link to={`/blog/${blog.slug}`} className="card-read-link">
372+
<Link to={blogPath} className="card-read-link">
358373
Read →
359374
</Link>
360375
</div>

0 commit comments

Comments
 (0)