From fc8ce30a9d6d4191a207c88900794d8ab2067d5b Mon Sep 17 00:00:00 2001 From: Sat Naing Date: Tue, 20 Sep 2022 22:20:20 +0630 Subject: [PATCH] Update breadcrumbs for page numbers --- src/components/Breadcrumbs.astro | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/Breadcrumbs.astro b/src/components/Breadcrumbs.astro index 28cfe2e..63c5423 100644 --- a/src/components/Breadcrumbs.astro +++ b/src/components/Breadcrumbs.astro @@ -6,10 +6,17 @@ const currentUrlPath = Astro.url.pathname.replace(/\/+$/, ""); // eg: /tags/tailwindcss => ['tags', 'tailwindcss'] const breadcrumbList = currentUrlPath.split("/").slice(1); -// if breadcrumb is Home > Post > 'article-name' -// replace 'article-name' to 'current post' -if (breadcrumbList[0] === "posts" && breadcrumbList.length > 1) { - breadcrumbList.splice(1, 1, "current post"); +// if breadcrumb is Home > Posts > 1 +// replace Posts with Posts (page number) +if ( + (breadcrumbList[0] === "posts" && !isNaN(Number(breadcrumbList[1]))) || + (breadcrumbList[0] === "posts" && breadcrumbList.length < 2) +) { + breadcrumbList.splice( + 0, + 2, + `Posts (page ${breadcrumbList[1] ? breadcrumbList[1] : 1})` + ); } ---