Skip to content

Commit c89d3cb

Browse files
authored
Merge pull request #1826 from iitzIrFan/feat/blog-card-clickable
feat: make blog cards clickable for improved navigation
2 parents fe998f7 + 034aca0 commit c89d3cb

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";
@@ -234,6 +235,8 @@ export default function Blogs() {
234235
const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
235236
const readingTime = blog.readingTime ?? 1;
236237
const authors = getAuthorProfiles(blog.authors || []);
238+
const history = useHistory();
239+
const blogPath = `/blog/${blog.slug}`;
237240

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

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

262275
{/* Description */}
@@ -303,6 +316,7 @@ const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
303316
target="_blank"
304317
rel="noopener noreferrer"
305318
title={author.name}
319+
onClick={(event) => event.stopPropagation()}
306320
>
307321
{author.imageUrl ? (
308322
<img
@@ -341,6 +355,7 @@ const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
341355
target="_blank"
342356
rel="noopener noreferrer"
343357
title={author.name}
358+
onClick={(event) => event.stopPropagation()}
344359
>
345360
{author.name}
346361
</Link>
@@ -364,7 +379,7 @@ const BlogCard = ({ blog }: { blog: (typeof blogs)[number] }) => {
364379
</div>
365380

366381
{/* Read link */}
367-
<Link to={`/blog/${blog.slug}`} className="card-read-link">
382+
<Link to={blogPath} className="card-read-link">
368383
Read →
369384
</Link>
370385
</div>

0 commit comments

Comments
 (0)