Skip to content

Commit 09dd091

Browse files
fix: blog post listing axe
1 parent 1419dee commit 09dd091

3 files changed

Lines changed: 38 additions & 20 deletions

File tree

‎apps/ui/locales/en.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"title": "Blog",
113113
"description": "Tutorials, product updates, and engineering insights.",
114114
"loadMore": "Load More Articles",
115+
"postsListAriaLabel": "Blog posts",
115116
"seeAllRelated": "See all {category} articles",
116117
"articles": "Articles",
117118
"relatedPosts": "Related Posts",

‎apps/ui/src/components/blog/BlogPostRow.tsx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import {
33
AuthorAvatars,
44
} from "@/components/elementary/AuthorAvatars"
55
import { HeroContainerBorder } from "@/components/elementary/HeroContainer"
6-
import { type BlogCategory, combineAuthors } from "@/lib/blog-utils"
6+
import {
7+
BLOG_DATE_FORMAT,
8+
type BlogCategory,
9+
combineAuthors,
10+
} from "@/lib/blog-utils"
711
import { formatDate } from "@/lib/dates"
812
import { Link } from "@/lib/navigation"
913
import { cn } from "@/lib/styles"
@@ -31,7 +35,7 @@ export function BlogPostRow({
3135

3236
return (
3337
<HeroContainerBorder asChild>
34-
<div
38+
<li
3539
className={cn(
3640
"group/blog-post-row relative grid items-center gap-x-4 gap-y-3 px-5 py-4 transition-[border-color] duration-300 sm:px-8",
3741
"grid-cols-[auto_auto_auto_1fr] lg:grid-cols-[1fr_7rem_10rem_9rem]",
@@ -64,10 +68,15 @@ export function BlogPostRow({
6468
)}
6569
</div>
6670

67-
<span className="text-strapi-gray-400 col-span-4 text-left text-sm whitespace-nowrap sm:col-span-1 sm:text-right lg:text-base">
68-
{publishedAt ? formatDate(publishedAt, "MMMM D, YYYY") : ""}
69-
</span>
70-
</div>
71+
{publishedAt ? (
72+
<time
73+
dateTime={formatDate(publishedAt, "YYYY-MM-DD")}
74+
className="text-strapi-gray-400 col-span-4 text-left text-sm whitespace-nowrap sm:col-span-1 sm:text-right lg:text-base"
75+
>
76+
{formatDate(publishedAt, BLOG_DATE_FORMAT)}
77+
</time>
78+
) : null}
79+
</li>
7180
</HeroContainerBorder>
7281
)
7382
}

‎apps/ui/src/components/blog/BlogPostsList.tsx‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import type { Locale } from "next-intl"
3+
import { type Locale, useTranslations } from "next-intl"
44
import { useState, useTransition } from "react"
55

66
import { type BlogPost, getBlogPostPublishDate } from "@/lib/blog-utils"
@@ -40,6 +40,7 @@ export function BlogPostsList({
4040
excludeCategorySlugs,
4141
excludeSlugs,
4242
}: BlogPostsListProps) {
43+
const t = useTranslations("blog")
4344
const [posts, setPosts] = useState<readonly BlogPost[]>(initialPosts)
4445
const [offset, setOffset] = useState(initialOffset)
4546
const [hasMore, setHasMore] = useState(initialOffset < total)
@@ -66,19 +67,26 @@ export function BlogPostsList({
6667

6768
return (
6869
<div className="flex flex-col gap-4">
69-
{posts
70-
.filter((post) => typeof post.slug === "string" && post.slug.length > 0)
71-
.map((post) => (
72-
<BlogPostRow
73-
key={post.documentId}
74-
title={post.title ?? ""}
75-
slug={post.slug as string}
76-
publishedAt={getBlogPostPublishDate(post)}
77-
author={post.author}
78-
coauthors={post.coauthors ?? undefined}
79-
category={post.category}
80-
/>
81-
))}
70+
<ul
71+
aria-label={t("postsListAriaLabel")}
72+
className="flex list-none flex-col gap-4 pl-0"
73+
>
74+
{posts
75+
.filter(
76+
(post) => typeof post.slug === "string" && post.slug.length > 0
77+
)
78+
.map((post) => (
79+
<BlogPostRow
80+
key={post.documentId}
81+
title={post.title ?? ""}
82+
slug={post.slug as string}
83+
publishedAt={getBlogPostPublishDate(post)}
84+
author={post.author}
85+
coauthors={post.coauthors ?? undefined}
86+
category={post.category}
87+
/>
88+
))}
89+
</ul>
8290

8391
{hasMore && (
8492
<div className="flex justify-center py-10">

0 commit comments

Comments
 (0)